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
posted on 2018-07-10 12:12 fox_charon 阅读(256) 评论(0) 编辑 收藏 举报