当前位置:网站首页>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 .
边栏推荐
- 一文了解MySQL事务隔离级别
- 一个满分的项目文档是如何书写的|得物技术
- Embedded-c Language-3
- composer安装报错:No composer.lock file present.
- Rider 设置选中单词侧边高亮,去除警告建议高亮
- It is forbidden to copy content JS code on the website page
- Machine learning compilation lesson 2: tensor program abstraction
- 深耕5G,芯讯通持续推动5G应用百花齐放
- The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale
- Writing method of twig array merging
猜你喜欢
随机推荐
The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale
Judge whether a number is a prime number (prime number)
composer安装报错:No composer.lock file present.
Learnopongl notes (II) - Lighting
Error in composer installation: no composer lock file present.
Timestamp strtotime the day before or after the date
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
First day of learning C language
通过proc接口调试内核代码
CMake教程Step5(添加系统自检)
Rider 设置选中单词侧边高亮,去除警告建议高亮
Wechat official account web page authorization login is so simple
PHP人才招聘系统开发 源代码 招聘网站源码二次开发
【729. 我的日程安排錶 I】
[61dctf]fm
[729. My schedule I]
浏览器渲染原理以及重排与重绘
ternary operator
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword









