想取SHU中倒数第二大的数值,这条SQL语句怎么写?
如:
id(int) shu(int)
1 1
2 1
3 55
4 55
5 66
6 66
取出来的结果就是55。。
4 个解决方案
#1
select max(shu) from 表 where shu<>(select max(shu) from 表)
#2
create table ma (id int,shu int)
insert into ma
select 1, 1 union
select 2, 1 union
select 3, 55 union
select 4, 55 union
select 5, 66 union
select 6, 66
select top 1 * from (
select distinct shu from ma ) a
where a.shu not in (
select top 1 * from (
select distinct shu from ma ) a order by shu desc) order by shu desc
insert into ma
select 1, 1 union
select 2, 1 union
select 3, 55 union
select 4, 55 union
select 5, 66 union
select 6, 66
select top 1 * from (
select distinct shu from ma ) a
where a.shu not in (
select top 1 * from (
select distinct shu from ma ) a order by shu desc) order by shu desc
#3
这条句子要在ASP里用的,所以好像上面的不太好用
#4
好句好句,谢了,搞定
#1
select max(shu) from 表 where shu<>(select max(shu) from 表)
#2
create table ma (id int,shu int)
insert into ma
select 1, 1 union
select 2, 1 union
select 3, 55 union
select 4, 55 union
select 5, 66 union
select 6, 66
select top 1 * from (
select distinct shu from ma ) a
where a.shu not in (
select top 1 * from (
select distinct shu from ma ) a order by shu desc) order by shu desc
insert into ma
select 1, 1 union
select 2, 1 union
select 3, 55 union
select 4, 55 union
select 5, 66 union
select 6, 66
select top 1 * from (
select distinct shu from ma ) a
where a.shu not in (
select top 1 * from (
select distinct shu from ma ) a order by shu desc) order by shu desc
#3
这条句子要在ASP里用的,所以好像上面的不太好用
#4
好句好句,谢了,搞定