取最大/最小的两个值
表格如下:
id num
01 2
02 4
03 7
04 0
05 1
06 3
07 9
08 11
希望得到如下结果
id num
08 11
07 9
05 1
04 0
[解决办法]
create table #ta(id varchar(5), num int)insert #taselect '01', 2union all select '02', 4union all select '03', 7union all select '04', 0union all select '05', 1union all select '06', 3union all select '07', 9union all select '08', 11select * from( select top 2 id, numfrom #ta order by num)t1union allselect * from(select top 2 id, numfrom #ta order by num desc)t2order by num desc