mysql查询数据排序后,将某一条数据放置到第一条
例子:比如查询表,查出100条数据,要单独将叫王五的显示在列表的第一条,这个王五的身份证号等于999(身份证是唯一的)
1.通过case when+排序
select (case when a.身份证='999' then 0 else 1 end) as flag,a.* from student a order by flag asc;
这是置顶显示,置底的话order by flag desc反序排列即可;
2.通过union
select * from student where 身份证='999' union all select * from student where 身份证<>'3';
JAVA修炼塔,技术世界的探知与交流,欢迎你的加入-----群号:535296702

浙公网安备 33010602011771号