首先看一张表:
colid | vyear | area | cast |
---|---|---|---|
,31,32,21,12 | 2014 | 1 | 15 |
,32,33,34,35,21, | 2014 | 2 | 16 |
,33,34,36,39,40 | 2011 | 3 | 17 |
当我们需要查询这张表中,colid含有32的行,
那么可以用FIND_IN_SET()
SQL如下:
SELECT * FROM table WHERE FIND_IN_SET('32', colid);强制排序的话可以这么写:
SELECT * FROM table WHERE area IN(2,1,3) ORDER BY find_in_set(area,'2,1,3');