日期:2014-05-17  浏览次数:20317 次

关于平均值的SQL语句,求帮助
假设有下面的表 
id 列A
1   1
2   1
3   3
4   6
5   6
6   9
7   11
8   11
9   11
求列A去掉最大值最小值(即去掉1跟11)的平均值的SQL语句

------解决方案--------------------
select avg(A) from 表 
where a!=(select max(a) from 表) and a!=(select min(a) from 表)
------解决方案--------------------
select avg(列A)
from tab 
where id not in (select top 1 id from tab order by 列A ,id)
and id not in (select top 1 id from tab order by 列A desc,id desc)