按IN顺序排序
select * from table_name where doc_id IN ('1dba', 'c20a', '907b')
mysql返回的结果集的排序是按照入库顺序给出的,若希望按照doc_id列表的先后顺序进行排序,
select * from table_name where doc_id IN ('1dba', 'c20a', '907b') order by FIND_IN_SET('1dba', 'c20a', '907b')
ORDER BY + 字段 + 排序方式
使用前:
SELECT `goods_id` FROM `sdb_goods` LIMIT 0 , 30
使用后
SELECT `goods_id` FROM `sdb_goods` ORDER BY `goods_id` = 4 DESC LIMIT 0 , 30
`goods_id` = 4 的商品真排上来了,这个样子就省事情了,哈哈
再来完善下,
SELECT `goods_id` FROM `sdb_goods` ORDER BY `goods_id` = 4 DESC, `goods_id` ASC LIMIT 0 , 30