当前位置: 代码迷 >> DB2 >> 查询表A中成绩分数第3高的记要,至少2个query
  详细解决方案

查询表A中成绩分数第3高的记要,至少2个query

热度:1064   发布时间:2013-02-26 00:00:00.0
查询表A中成绩分数第3高的记录,至少2个query
表A
P_ID SCORE
1 100
2 99
3 98
4 98
5 97

------解决方案--------------------------------------------------------
select * from (
select SCORE,row_number() over(order by SCORE) as pm from tt )a where pm=3
------解决方案--------------------------------------------------------
select * from 表 where P_ID in (
  select P_ID from (
    select P_ID,row_number() over(order by SCORE) as ID from 表
  ) a 
  where pm=3
)

------解决方案--------------------------------------------------------
select * from 表 where score in (
  select score from (
    select score,row_number() over(order by SCORE) as ID from 表
  ) a  
  where ID=3
)

------解决方案--------------------------------------------------------
select * from 表A t
where 3=(select count(*) from 表A where SCORE>=t.SCORE)
  相关解决方案