当前位置:网站首页> mysql中取出json字段的小技巧
mysql中取出json字段的小技巧
2022-07-05 16:42:00 【1024问】
mysql取出json字段技巧
mysql中使用函数JSON_EXTRACT()
spark sql中使用get_json_object()
mysql取json,在不知道key情况下,取他的value详细值
mysql取出json字段技巧有时候会将一些信息以json形式存在数据库中,如果太长的话,在取的过程中sql运行会比较慢,如果只取某些键值的话会比较浪费
mysql中使用函数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中使用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取json,在不知道key情况下,取他的value详细值{ "selects" :{ "20071090" :{ "NN" : 41,"LXFS1" : "12365","GH" : "20071090","RZZW" : "办公室主任","sxzym" : "园林植物与观赏园艺","ZC" : "副教授","XGW" : "行政管理后勤","XB" : "男","ZZMM" : "中共党员","ZWZC" : "高级职称","MZ" : "汉","CSRQ" : 307123200000,"XL" : "硕士","selectKey" : "20071090","XM" : "张三","GZBM" : "办公室","PZGW" : "副教授三级岗位","XW" : "农学硕士" }}}
在这个mysql数据库下想取一个姓名标红是如内容如上图
建立视图,取这个字段的姓名,由于他的key:"20071090" 是动态的不确定,而且在这个地方只会出现一次,首先我取第一层key==>selects下的值
SELECT ZDLSXM->'$.selects' from VI_YXGR
在这个基础上,再取下一层,由于这层是动态的key,不能使用第一步的 ZDLSXM->'$.selects' 那种方法,所以我选择substring_index 方法 去掉大括号的方式来,再使用CONCAT() 拼接成为新的json,如下图标红的地方删除掉
SELECT CONCAT("{",substring_index(substring_index(ZDLSXM->'$.selects', '{', -1),"}",1),"}") from VI_YXGR
再包装一层就可以取道这个名称了
SELECT SE_ZDLSXM->'$.name' AS ZDLSXM from (SELECT CONCAT("{",substring_index(substring_index(ZDLSXM->'$.selects', '{', -1),"}",1),"}") as SE_ZDLSXM from VI_YXGR) sss
以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。
边栏推荐
- 【性能测试】jmeter+Grafana+influxdb部署实战
- Jarvis OJ 简单网管协议
- 外盘期货平台如何辨别正规安全?
- Deeply cultivate 5g, and smart core continues to promote 5g applications
- Read the basic grammar of C language in one article
- PHP人才招聘系统开发 源代码 招聘网站源码二次开发
- 2022 年 Q2 加密市场投融资报告:GameFi 成为投资关键词
- The second day of learning C language for Asian people
- American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
- 手机开证券账户安全吗?怎么买股票详细步骤
猜你喜欢
Embedded -arm (bare board development) -2
Etcd build a highly available etcd cluster
腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
WSL2.0安装
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
Embedded-c Language-1
Using C language to realize palindrome number
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
Browser rendering principle and rearrangement and redrawing
Machine learning compilation lesson 2: tensor program abstraction
随机推荐
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
Detailed explanation of printf() and scanf() functions of C language
Is it safe to open an account for digging wealth stocks? How is it safe to open a stock account?
goto Statement
【剑指 Offer】66. 构建乘积数组
[wechat applet] read the life cycle and route jump of the applet
CMake教程Step5(添加系统自检)
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
tf. sequence_ Mask function explanation case
Error in composer installation: no composer lock file present.
Deep dive kotlin synergy (XXI): flow life cycle function
[Jianzhi offer] 62 The last remaining number in the circle
Is it safe for qiniu business school to open a stock account? Is it reliable?
Embedded-c Language-2
拷贝方式之DMA
How to write a full score project document | acquisition technology
stirring! 2022 open atom global open source summit registration is hot!
Read the basic grammar of C language in one article
干货!半监督预训练对话模型 SPACE
调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%