sql -- 利用order by 排名作弊

Posted 8013-cmf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql -- 利用order by 排名作弊相关的知识,希望对你有一定的参考价值。

表结构:

技术图片

需求:

技术图片

方法1:union

select * from (select *  from user_level where id in (2,4,6) order by user_total desc ) a
union
(select * from (select *  from user_level where id not in (2,4,6) order by user_total desc ) b)

方法2:直接在order by加

select * from user_level order by id in (2,4,6) desc,user_total desc ;

技术图片

以上是关于sql -- 利用order by 排名作弊的主要内容,如果未能解决你的问题,请参考以下文章

ROWNUMBER() OVER( PARTITION BY COL1 ORDER BY COL2)用法,先分组,然后在组内排名,分组计算等

SQL - GROUP BY和ORDER BY MIN

SQL 简单的 ORDER BY

mysql:优化查询 w/混合升序 ORDER BY

sql不用order by查找第二的思路

*18查找当前薪水排名第二多的员工编号emp_no薪水salarylast_name以及first_name,不准使用order by