如商品订单信息表
查询需要信息并做模糊处理查询:
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() 去掉 "" 号
原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/267384.html