mysql查询json类型字段提取需要类
2022/6/14 2:20:09
本文主要是介绍mysql查询json类型字段提取需要类,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
如商品订单信息表
查询需要信息并做模糊处理查询:
select t.goods_order_id orderId, t.goods_id goodsId, t.goods_spe_id speId, t.goods_order_no orderNumber, t.number orderGoodsNum, JSON_EXTRACT(t.buy_customer,'$.nickName') as nickName, JSON_EXTRACT(t.receive_customer,'$.name') as receiver, JSON_EXTRACT(t.receive_customer,'$.phone') as mobile, JSON_EXTRACT(t.receive_customer,'$.area[0].text') as addressOne, JSON_EXTRACT(t.receive_customer,'$.area[1].text') as addressTwo, JSON_EXTRACT(t.receive_customer,'$.area[2].text') as addressThree, JSON_EXTRACT(t.receive_customer,'$.area[3].text') as addressFour, JSON_EXTRACT(t.receive_customer,'$.address') as address, JSON_EXTRACT(t.goods_shot_cut,'$.goods.name') as goodName, JSON_EXTRACT(t.goods_shot_cut,'$.spe.speName') as speName, JSON_EXTRACT(t.logistics_info,'$.logisticsCompany') as logisticName, JSON_EXTRACT(t.logistics_info,'$.logisticsNo') as expressNumber, DATE_FORMAT(t.creation_time,'%Y-%m-%d %H:%i:%s') createTime from merchant_db.t_mall_goods_order t where t.store_id = #{storeId} and t.status != 0 and t.status != -10 <if test="orderStatus!=null and orderStatus!='' and orderStatus!= 0 and orderStatus!= -10 "> and t.status = #{orderStatus} </if> <if test="mobile!=null and mobile!=''"> and JSON_EXTRACT(t.receive_customer, '$."phone"') like CONCAT('%',#{mobile},'%') </if> <if test="receiver!=null and receiver!=''"> and JSON_EXTRACT(t.receive_customer, '$."name"') like CONCAT('%',#{receiver},'%') </if> <if test="userName!=null and userName!=''"> and JSON_EXTRACT(t.buy_customer, '$."userName"') like CONCAT('%',#{userName},'%') </if> <if test="nickName!=null and nickName!=''"> and JSON_EXTRACT(t.buy_customer, '$."nickName"') like CONCAT('%',#{nickName},'%') </if> <if test="commodityName!=null and commodityName!=''"> and JSON_EXTRACT(t.goods_shot_cut, '$.goods."name"') like CONCAT('%',#{commodityName},'%') </if> <if test="orderNumber!=null and orderNumber!=''"> and t.goods_order_no like CONCAT('%',#{orderNumber},'%') </if> <if test=" startTime!=null and startTime!= ''"> and t.creation_time >= #{startTime} </if> <if test=" endTime != null and endTime != ''"> and DATE_ADD(str_to_date(#{endTime}, '%Y-%m-%d'),INTERVAL 1 DAY) > t.creation_time </if> order by t.creation_time desc
mysql 取json字符串字段下的某个键的值
要求:mysql版本5.7及以上
由于json的键值是带双引号。所以需要去掉双引号。1.使用replace()做替换
select replace(JSON_EXTRACT(infoJson,'$.uid'),'"','') uid from users 或
JSON.parse(orderResp.getExpressNumber()).toString() 去掉 "" 号
这篇关于mysql查询json类型字段提取需要类的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-21Vue3教程:新手入门到实践应用
- 2024-12-21VueRouter4教程:从入门到实践
- 2024-12-20Vue3项目实战:从入门到上手
- 2024-12-20Vue3项目实战:新手入门教程
- 2024-12-20VueRouter4项目实战:新手入门教程
- 2024-12-20如何实现JDBC和jsp的关系?-icode9专业技术文章分享
- 2024-12-20Vue项目中实现TagsView标签栏导航的简单教程
- 2024-12-20Vue3入门教程:从零开始搭建你的第一个Vue3项目
- 2024-12-20从零开始学习vueRouter4:基础教程
- 2024-12-20Vuex4课程:新手入门到上手实战全攻略