工作中遇到问题:
需要查询表中某个字段不包含某个指定字符串的问题,以及查询json数据中某个key对应的value值。
问题1:查询 user_id 不包含 ‘@’ 字符的数据
数据如下:
id |
user_id |
51 |
jingi@ctfo.com |
52 |
1392653265887330305 |
需要筛选出 user_id 中不包含 @ 字符的数据。
sql 如下:
select id,user_id,create_time from 表 where locate('@', user_id) = 0
问题2:查询json数据中某个key对应的value值
数据如下:
id |
image |
51 |
[{“attachmentId”:“1637076042379120640”,“name”:“001.jpg”,“url”:“http://ip:88/devicemaintenance/2023/06/08/001_110559217.jpg”},{“attachmentId”:“1637076732683071488”,“name”:“001.jpg”,“url”:“http:/ip:88/devicemaintenance/2023/06/08/001_110604472.jpg”}] |
**需要查询 image 中 url 的值 ,并去除引号 " **
sql 如下:
select id,trim('"' from JSON_EXTRACT ( t.device_image_new -> '$[1]', '$.url' ))image from 表