数据
  |Field1| Field2|  Field3|
  | F1   |   x1         1
  | F2   |   xx1        3
  | F1   |   x1         2
  | F1   |   x2         2
  | F1   |   x2         3
  | F2   |   xx1        4
  | F2   |   xx2        5
  | F3   |   xxx1       6
  | F3   |   xxx2       2
  | F3   |   xxx2       3  结果
  F1        x1          3
  F1        x2          5
  F2        xx1         7
  F2        xx2         5
  F3        xxx1        6
  F3        xxx1        5

解决方案 »

  1.   


    select Field1,Field2, Field3=sum(Field3)
    from tb
    group  by Field1,Field2
      

  2.   

    select Field1,Field2,[SUM]=sum(Field3) from tb group by Field1,Field2
      

  3.   

      
      Select Field1,Field2,Sum(Field3)
      from tb
      Group by Field1,Field2?
      

  4.   


    select Field1,Field2 , sum(Field3) from tb group by Field1,Field2
      

  5.   


    --> 测试数据:[TB]
    if object_id('[TB]') is not null drop table [TB]
    create table [TB]([Field1] varchar(2),[Field2] varchar(4),[Field3] int)
    insert [TB]
    select 'F1','x1',1 union all
    select 'F2','xx1',3 union all
    select 'F1','x1',2 union all
    select 'F1','x2',2 union all
    select 'F1','x2',3 union all
    select 'F2','xx1',4 union all
    select 'F2','xx2',5 union all
    select 'F3','xxx1',6 union all
    select 'F3','xxx2',2 union all
    select 'F3','xxx2',3select Field1,Field2,sum(Field3) from [TB] 
    group by Field1,Field2
    /*
    Field1 Field2             
    ------ ------ ----------- 
    F1     x1     3
    F1     x2     5
    F2     xx1    7
    F2     xx2    5
    F3     xxx1   6
    F3     xxx2   5(所影响的行数为 6 行)*/drop table TB
      

  6.   

    select Field1,Field2,sum(Field3) as Field3
    from tableName
    group by Field1,Field2
      

  7.   

    select Field1,Field2,sum(Field3) as Field3
    from tableName
    group by Field1,Field2