mysql 根据传入的数据排序的问题

2014-08-05 11:28:50 +08:00
 hellohacker
如下:
select count(*) as num from a where id in (11,12,9,4,15) group by id;

这样输出数据后,不是按照 id的数据顺序 11,12,9,4,15 输出的

求解决方案 3Q!
3321 次点击
所在节点    MySQL
3 条回复
yangqi
2014-08-05 11:34:18 +08:00
ORDER BY FIELD(ID,11,12,9,4,15)
hcy
2014-08-05 11:41:16 +08:00
order by field(id ,11,12,9,4,15)
试下这个。
hellohacker
2014-08-05 11:54:25 +08:00
@yangqi
@hcy

3Q 2 位 问题已解决

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/126181

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX