数据表字段结构如下
字段名     a(int)        b(vachar)
记录          1             a
            1              a
            1              b
            1              c
要求sql语句计算b字段不相同时a字段的和,也就是上面表运算结果应为3请各位大虾给出一条sql语句的实现方法,谢过!

解决方案 »

  1.   

    select sum(a) from (select max(a) as a from table group by b) temp
      

  2.   

    b字段相同 a字段不同的情况呢 取哪个值?
    如:
    1  d
    2  d
    3  d
      

  3.   

    wym840713 ,谢谢!  没有这种情况! 
      

  4.   

    ------------------------------------------------------------
    go
    declare @T table(a int,b varchar(20))
     
    insert into @T select 1,'a'
    insert into @T select 1,'a'
    insert into @T select 1,'b'
    insert into @T select 1,'c'select count(c.hh) from (select count(*) as hh from @T group by b) as c
    go
    ------------------------------------------------------------results:
    ------------
    条数
    3
    ------------