查询:
SELECT distinct
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
Where 1=1
输出:
排名:1 |服务:test1
排名:2 |服务:test2
排名:3 |服务:test3
我如何仅显示2级?
我尝试了此方法,但没有用:
SELECT distinct
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
Where rank = 2
有什么主意吗?
答案 0 :(得分:1)
您可以尝试使用子查询,因为where
不能使用别名来做条件。
SELECT * FROM (
SELECT
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
) t1
where rank = 2
答案 1 :(得分:1)
将您的查询放入子查询中
select *
from
(
SELECT distinct
rank() OVER (ORDER BY p.service) as rank,
p.service,
From table_service
) sub
Where rank = 2;
答案 2 :(得分:1)
为什么使用等级?大多数数据库支持offset/fetch
或类似的东西:
select p.service,
from table_service p
order by p.service
offset 1 fetch first 1 row only;