经常遇到类似‘1,4,7,5,36,14’这样的字符串,在数据库里面怎么处理呢?!
order
id name total goodIds
1 订单1 5 4,14,6,7,46
2 订单2 7 1,11,111,32,24
3 订单3 3 1,14,7
4 订单4 4 1,13, 4,7
单个查找:查出包涵goodId为1的的订单
- select * from order where CONCAT(‘,‘,goodIds,‘,‘) LIKE CONCAT(‘%,‘,1,‘,%‘)
- select * from order where FIND_IN_SET(‘1‘,goodIds);
有个需求:统计goodId的个数>3
- select * from order where goodIds like ‘%,%,%,%‘
- select * from order where goodIds REGEXP ‘([0-9]+,){3}‘ ---这个是正则匹配
时间: 2024-10-22 03:05:34