sql列组显示请求的列组编号
查询: 输出:sql列组显示请求的列组编号,sql,rank,Sql,Rank,查询: 输出: 排名:1 |服务:测试1 排名:2 |服务:测试2 排名:3 |服务:测试3 如何仅显示排名2 我尝试过这个,但不起作用: SELECT distinct rank() OVER (ORDER BY p.service) as rank, p.service, From table_service Where 1=1 有什么想法吗?您可以尝试使用子查询,因为where不能使用别名来执行条件 SELECT distinct rank() OVER (ORDER BY p.s
排名:1 |服务:测试1
排名:2 |服务:测试2
排名:3 |服务:测试3
如何仅显示排名2 我尝试过这个,但不起作用:
SELECT distinct
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
Where 1=1
有什么想法吗?您可以尝试使用子查询,因为
where
不能使用别名来执行条件
SELECT distinct
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
Where rank = 2
将查询放入子查询:
SELECT * FROM (
SELECT
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
) t1
where rank = 2
为什么使用秩?大多数数据库支持
offset/fetch
或类似的功能:
select *
from
(
SELECT distinct
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
) sub
Where rank = 2;
你真是个天才!你真是个天才!
select p.service,
from table_service p
order by p.service
offset 1 fetch first 1 row only;