欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Mysql查询数据返回排序

程序员文章站 2022-05-12 18:13:32
...
例如有这样一条语句

select uid from user where uid = 70 or uid =68 or uid = 69;

mysql返回的是

68
69
70

如何让mysql返回

70
68
69

这样的结果,就是按照where的条件先后来返回.

回复内容:

例如有这样一条语句

select uid from user where uid = 70 or uid =68 or uid = 69;

mysql返回的是

68
69
70

如何让mysql返回

70
68
69

这样的结果,就是按照where的条件先后来返回.

SELECT id, name
FROM mytable
WHERE name IN ('B', 'A', 'D', 'E', 'C')
ORDER BY FIELD(name, 'B', 'A', 'D', 'E', 'C')

网上随便找下就有了

select uid from user where uid in( 70 ,68 , 69) order by fine_in_set('uid','70,68,69');

select uid from user where uid = 70 or uid =68 or uid = 69 order by uid desc

select uid from user where uid = 70 or uid =68 or uid = 69 order by uid desc;