是求最大值还是求总值??
最大值
select A, max(B) as MAX_B from tablename
group by A总和
select A, sum(b) as sum_b from tablename
group by A
最大值
select A, max(B) as MAX_B from tablename
group by A总和
select A, sum(b) as sum_b from tablename
group by A
select A, max(B) as MAX_B from tablename
group by A总和
select A, sum(b) as sum_b from tablename
group by A
create table abc(A int,B int)
insert into abc
select 10,1
union all
select 10,2
union all
select 10,3
union all
select 11,1
union all
select 11,2
union all
select 11,3select A, sum(b) as sum_b from (select A,max(b) as B from abc group by A) a
group by A with ROLLUP--删除测试数据
drop table abc
即求
A B
10 30
11 30
这时再求B列的Sum值
select sum(b) from student where b=
(select max(b) from table) b列裡面最大值和
我再表述一下:
1、第一步是去除A列中的重复,只保留B列中是最大值的行
2、第一步是对筛选后的记录,求B列的和
Select A,Max(B) As B from 表 Group By A第二步:
Select SUM(B) from (Select A,Max(B) As B from 表 Group By A) T