SQL : 把特定的数据排前面 & 分别查询几组数据的最大值

把特定的数据排前面 :

比如说,把没有审核身份证的人排最前面,然后再按userId正序排。

select case when idcardverified = 1 then 0 else 1 end flag,o.* from (select id,mobile,nickname,idcardverified from users where mobile = 13800000000 or nickname = '关于衣服') o order by flag asc,id asc

分别查询几组数据的最大值:

比如说,有同学A B C,他们传了多次坐标,要查询他们最新的坐标。

SELECT * FROM `map_position` where ctime in (select max(ctime) from `map_position` group by userId) order by userId asc

猜你喜欢

转载自www.cnblogs.com/foxcharon/p/9288342.html
今日推荐