如何写去掉一个最大值,去掉一个最小值计算结果

fflcat 2011-05-06 03:04:52
例:

create table test
(a int,b int)

insert test
select 1,2
UNION all
select 2,2
union all
select 3,4
union all
select 21,32

按要求,我需要去掉a列的最小值1 和最大值 21 对应记录,之后计算剩下结果的b列值,谢谢,如何做
...全文
653 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cd731107 2011-05-06
  • 打赏
  • 举报
回复
select * from test where a not in (select max(a),min(a) from test)
gogodiy 2011-05-06
  • 打赏
  • 举报
回复

create table t1
(
a int,
b int
)
insert into t1
select 1,2 union all
select 2,2 union all
select 3,4 union all
select 21,32
select * from t1

;with aaa as
(select a from t1
except
select MIN(a) from t1
except
select MAX(a) from t1)
select SUM(b) as b from t1 where a in (select a from aaa)
duoxu1983 2011-05-06
  • 打赏
  • 举报
回复
select sum(col)-max(col)-min(col) as total from tb
Shawn 2011-05-06
  • 打赏
  • 举报
回复
SELECT avgb=AVG(t.b) FROM
(SELECT rowno=ROW_NUMBER() OVER(ORDER BY a, GETDATE()),* FROM test) t
WHERE t.rowno <> 1 AND t.rowno <> (SELECT COUNT(*) FROM test)
/*
avgb
-----------
3
*/
twglinda 2011-05-06
  • 打赏
  • 举报
回复
用什么数据库的啊.什么好用啊.不知道
michaelgong 2011-05-06
  • 打赏
  • 举报
回复

select b from test c inner join (select MAX(a) as e,MIN(a) as f from test) d on c.a!=d.e and c.a!=d.f

b
-----------
2
4

(2 行受影响)

Tosp2012 2011-05-06
  • 打赏
  • 举报
回复

select sum(b) as b from Test a where a.a>( select min(a) as a from Test ) and a.a< ( select max(a) as a from Test)
michaelgong 2011-05-06
  • 打赏
  • 举报
回复

create table test
(a int,b int)

insert test
select 1,2
UNION all
select 2,2
union all
select 3,4
union all
select 21,32
select * from test
select c.* from test c inner join (select MAX(a) as e,MIN(a) as f from test) d on c.a!=d.e and c.a!=d.f

a b
----------- -----------
1 2
2 2
3 4
21 32

(4 行受影响)

a b
----------- -----------
2 2
3 4

(2 行受影响)


mustudent 2011-05-06
  • 打赏
  • 举报
回复

--2005 later
create table #test
(a int,b int)

Delete From #test
insert #test
select 1,2
UNION all
select 2,2
union all
select 3,4
union all
select 21,32
Union All
Select 1,2

Select a.a,a.b From
(Select Row_Number() Over(Order By a) As ROWID,* From #test) a
WHere ROWID >=2 And ROWID<=(Select Count(1)-1 From #Test)


xuyuchends 2011-05-06
  • 打赏
  • 举报
回复

select sum(t1.b) from test as t1
where exists(select * from test where t1.a<test.a)
and exists(select * from test where t1.a>test.a)
SQL77 2011-05-06
  • 打赏
  • 举报
回复
如果有两个最小值咋弄

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧