常常遇到相似‘1,4,7,5,36,14’這樣的字符串,在數據庫裏面怎麼處理呢?!數據庫
order字符串
id name total goodIdsselect
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}' ---這個是正則匹配