declare @tb table
(
ID int,
num int
)
insert @tb
select '01',89 union all
select '02',78 union all
select '03',69 union all
select '04',89 union all
select '05',78 union all
select '06',69 union all
select '07',69 union all
select '08',16
--取最大值
select num
from (select num from @tb group by num) t
where (
select count(1)
from (select num from @tb group by num)a where num>t.num
)=0
--第二大值
select num
from (select num from @tb group by num) t
where (
select count(1)
from (select num from @tb group by num)a where num>t.num
)=1
--第三大值
select num
from (select num from @tb group by num) t
where (
select count(1)
from (select num from @tb group by num)a where num>t.num
)=2
--第四大值
select num
from (select num from @tb group by num) t
where (
select count(1)
from (select num from @tb group by num)a where num>t.num
)=3
to liujianbabycome:你那个有问题哦, 得不到任何结果。要加一个等号(示例如下,测试数据与phantomMan相同)
select avgscore from class
where avgscore>=all(select avgscore from class)
to zzyhuian:排序后的某一条记录, 一般都是用两个top来做.