当前位置:网站首页>Tips for extracting JSON fields from MySQL
Tips for extracting JSON fields from MySQL
2022-07-05 17:14:00 【1024 questions】
mysql Take out json Field skills
mysql Using functions in JSON_EXTRACT()
spark sql Use in get_json_object()
mysql take json, In don't know key Under the circumstances , Take his value Detailed value
mysql Take out json Field skillsSometimes some information will be written in json Forms exist in the database , If it's too long , In the process of taking sql It will run slower , If you only take some key values, it will be more wasteful
mysql Using functions in JSON_EXTRACT()±—±---------------------------------------------------------------+| id | data |±—±---------------------------------------------------------------+| 1 | {“Tel”: “132223232444”, “name”: “david”, “address”: “Beijing”} || 2 | {“Tel”: “13390989765”, “name”: “Mike”, “address”: “Guangzhou”} |±—±---------------------------------------------------------------+select json_extract('{"name":"Zhaim","tel":"13240133388"}',"$.tel");spark sql Use in get_json_object()select get_json_object(i.extra, '$.sale_currency');select sum(get_json_object(i.extra, '$.sale_price') * i.count) as sale_price;mysql take json, In don't know key Under the circumstances , Take his value Detailed value { "selects" :{ "20071090" :{ "NN" : 41,"LXFS1" : "12365","GH" : "20071090","RZZW" : " Director of General Office ","sxzym" : " Garden plants and ornamental gardening ","ZC" : " associate professor ","XGW" : " Administration and logistics ","XB" : " male ","ZZMM" : " Party members ","ZWZC" : " Senior title ","MZ" : " han ","CSRQ" : 307123200000,"XL" : " master ","selectKey" : "20071090","XM" : " Zhang San ","GZBM" : " The office ","PZGW" : " Associate professor level III post ","XW" : " Master of Agriculture " }}}In this mysql If you want to get a name in red under the database, the content is as shown in the above figure

Create view , Take the name of this field , Because of his key:"20071090" Is dynamic uncertainty , And it will only appear once in this place , First I take the first floor key==>selects The next value
SELECT ZDLSXM->'$.selects' from VI_YXGR
On this basis , Take down another layer , Because this layer is dynamic key, Cannot use the first step ZDLSXM->'$.selects' That way , So I choose substring_index Method Remove the braces , Reuse CONCAT() Splicing becomes new json, Delete the red part of the following icon

SELECT CONCAT("{",substring_index(substring_index(ZDLSXM->'$.selects', '{', -1),"}",1),"}") from VI_YXGR

Another layer of packaging can take the name
SELECT SE_ZDLSXM->'$.name' AS ZDLSXM from (SELECT CONCAT("{",substring_index(substring_index(ZDLSXM->'$.selects', '{', -1),"}",1),"}") as SE_ZDLSXM from VI_YXGR) sss 
The above is personal experience , I hope I can give you a reference , I also hope you can support the software development network .
边栏推荐
- 腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
- CMake教程Step6(添加自定义命令和生成文件)
- Deeply cultivate 5g, and smart core continues to promote 5g applications
- 【7.7直播预告】《SaaS云原生应用典型架构》大咖讲师教你轻松构建云原生SaaS化应用,难题一一击破,更有华为周边好礼等你领!
- 一文了解Go语言中的函数与方法的用法
- 网上办理期货开户安全吗?网上会不会骗子比较多?感觉不太靠谱?
- 麻烦问下,DMS中使用Redis语法是以云数据库Redis社区版的命令为参考的嘛
- C how TCP restricts the access traffic of a single client
- Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
- The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
猜你喜欢

采用药丸屏的iPhone14或引发中国消费者的热烈抢购

PHP talent recruitment system development source code recruitment website source code secondary development

激动人心!2022开放原子全球开源峰会报名火热开启!

NPM installation

【机器人坐标系第一讲】

调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%

CMake教程Step4(安装和测试)

Error in composer installation: no composer lock file present.

npm安装

基于51单片机的电子时钟设计
随机推荐
It is forbidden to copy content JS code on the website page
How does the outer disk futures platform distinguish formal security?
stirring! 2022 open atom global open source summit registration is hot!
goto Statement
项目引入jar从私服Nexus 拉去遇到的一个问题
The second day of learning C language for Asian people
ThoughtWorks global CTO: build the architecture according to needs, and excessive engineering will only "waste people and money"
Embedded-c Language-3
基于51单片机的电子时钟设计
云安全日报220705:红帽PHP解释器发现执行任意代码漏洞,需要尽快升级
Embedded -arm (bare board development) -1
Deep dive kotlin synergy (XXI): flow life cycle function
[Jianzhi offer] 61 Shunzi in playing cards
Use byte stream to read Chinese from file to console display
C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
Read the basic grammar of C language in one article
Learnopongl notes (II) - Lighting
机器学习02:模型评估
启牛商学院股票开户安全吗?靠谱吗?