如题!举例说明

解决方案 »

  1.   

    select 字段1,sum(字段2) from table1 group by 字段1 试试
      

  2.   

    create table t(a int primary key,b int )
    insert into t select 1,2
    union select 1,3
    union select 1,4
    union select 2,5
    union select 2,6select a,sum(b) from t group by a
      

  3.   

    同意楼上的。
    group by 字段
      

  4.   

    SELECT A.row_no,A.col2,A.col3
    FROM match_cols A
    WHERE EXISTS(SELECT B.col2,B.col3
     FROM match_cols AS B
     WHERE A.col2=B.col2 AND A.col3=B.col3
     GROUP BY B.col2,B.col3
     HAVING COUNT(*)>1)
    ORDER BY A.col2,A.col3
      

  5.   

    SQL联机帮助搜索GROUP BY解释得详细多..
      

  6.   

    可以使用group by子句对数据库进行分组统计,在查询结果,每一组统计出一个结果。
      orson (tjhe)  :你不是昨天去参加华为的笔试了吧???呵呵:)
      

  7.   

    那我来接分;group by 常和having子句一起用,放在where 子句后,
      

  8.   

    1.
    select a,b,c
    from table
    group by a,b,c--這樣a,b,c相同的會不出現同 select distinct a,b,c from table2.統計
    select a,b,sum(c) as c
    from table
    group by a,b
      

  9.   

    联机帮助文档摘录:
    -----------------
    使用 GROUP BY 分组多行
    GROUP BY 子句用来为结果集中的每一行产生聚合值。如果聚合函数没有使用 GROUP BY 子句,则只为 SELECT 语句报告一个聚合值。以下示例返回分类 2 中每种产品已销售的单位数量:USE Northwind
    SELECT OrdD.ProductID AS ProdID,
           SUM(OrdD.Quantity) AS AmountSold
    FROM [Order Details] AS OrdD JOIN Products as Prd
         ON OrdD.ProductID = Prd.ProductID
         AND Prd.CategoryID = 2
    GROUP BY OrdD.ProductID下面是结果集:ProdID      AmountSold  
    ----------- ----------- 
    3           328         
    4           453         
    5           298         
    6           301         
    8           372         
    15          122         
    44          601         
    61          603         
    63          445         
    65          745         
    66          239         
    77          791         (12 row(s) affected)GROUP BY 关键字后面跟着列的列表,称为分组列。GROUP BY 子句限制结果集中的行;对于分组列中的每个非重复值只有一行。每个结果集行都包含与其分组列中特定值相关的汇总数据。