是求最大值还是求总值??
最大值
select  A, max(B) as MAX_B from tablename
group by A总和
select A, sum(b) as sum_b from tablename
group by A

解决方案 »

  1.   

    SELECT UNION(A) A,SUM(MAX(B))B FROM 表
      

  2.   

    最大值
    select  A, max(B) as MAX_B from tablename
    group by A总和
    select A, sum(b) as sum_b from tablename
    group by A
      

  3.   

    --测试数据
    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
      

  4.   

    SELECT DISTINCT(A) A,SUM(MIX(B)) B FROM TABLE
      

  5.   

    不对,我是要B列中每个最大值的求和
    即求
    A                    B
    10                   30
    11                   30
    这时再求B列的Sum值
      

  6.   

    select distinct a from table 不同的
    select sum(b) from student where b=
    (select max(b) from table) b列裡面最大值和
      

  7.   

    select sum(max) from ( select  A, max(B) as max from tablename group by A )楼主是这个意思吗?
      

  8.   

    select sum(max) from ( select distinct(A, max(B)) as max from tablename group by A )楼主是这个意思吗?
      

  9.   

    Select SUM(B) from (Select A,Max(B) As B from 表 Group By A) T
      

  10.   

    可能大家没有看懂我的意思
    我再表述一下:
    1、第一步是去除A列中的重复,只保留B列中是最大值的行
    2、第一步是对筛选后的记录,求B列的和
      

  11.   

    我写的就是啊。Select SUM(B) from (Select A,Max(B) As B from 表 Group By A) T第一步:
    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