当前位置:网站首页>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 .
边栏推荐
- Embedded-c Language-1
- High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
- [Web attack and Defense] WAF detection technology map
- dried food! Semi supervised pre training dialogue model space
- The third lesson of EasyX learning
- Embedded-c Language-4
- 张平安:加快云上数字创新,共建产业智慧生态
- 机器学习02:模型评估
- Error in compiling libssh2. OpenSSL cannot be found
- 叩富网开期货账户安全可靠吗?怎么分辨平台是否安全?
猜你喜欢

【剑指 Offer】63. 股票的最大利润

【729. 我的日程安排錶 I】

Jarvis OJ webshell analysis

【机器人坐标系第一讲】

中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户

项目引入jar从私服Nexus 拉去遇到的一个问题

基于51单片机的电子时钟设计

ternary operator

Browser rendering principle and rearrangement and redrawing

American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
随机推荐
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
C# TCP如何限制单个客户端的访问流量
Error in compiling libssh2. OpenSSL cannot be found
Three traversal methods of binary tree
winedt常用快捷键 修改快捷键latex编译按钮
[Jianzhi offer] 62 The last remaining number in the circle
Timestamp strtotime the day before or after the date
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
【剑指 Offer】63. 股票的最大利润
云安全日报220705:红帽PHP解释器发现执行任意代码漏洞,需要尽快升级
Wsl2.0 installation
Is it safe to open an account for digging wealth stocks? How is it safe to open a stock account?
国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」
ECU introduction
mysql中取出json字段的小技巧
调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
SQL删除重复数据的实例教程
How can C TCP set heartbeat packets to be elegant?
CMake教程Step2(添加库)
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)