我有一个表,
date(日期)  name(货物名称)    num(卖出数量) 
 1           a                 10
 1           b                 20
 2           c                 40
 3           a                 15
 4           a                 30
 5           b                 25
 5           c                 50我想统计这个月,每种货物的卖出数量,即希望得到如下结果集
 name(货物名称)    num(卖出数量) 
    a                 55
    b                 45
    c                 90请问这个SQL语句怎么写?3Q

解决方案 »

  1.   

    select sum(num) from table group by name
      

  2.   

    select 货物名称,sum(卖出数量) from youtable group by 货物名称
      

  3.   

    select 货物名称,sum(卖出数量) from youtable group by 货物名称
    where date(日期) = 这个月
      

  4.   


     同意这个全面!
      select 货物名称,sum(卖出数量) from youtable group by 货物名称
      where date(日期) = 这个月
      

  5.   


     同意这个全面!
      select 货物名称,sum(卖出数量) from youtable group by 货物名称
      where date(日期) = 这个月
      

  6.   

    select name, sum(num) as num
    from 表名
    where [date] = 这个月的月号
    group by name