select a.item_type,a.custdo_id,a.item_num,a.item_name,a.item_size,b.cust_do_get  from cust_item a join customer b
on a.custdo_id=b.custdo_id and b.cust_do_get='06-06-19' and a.item_type<>'冲印'
这条查询语句结果是
item_type custdo_id  item_num item_name   item_size          cust_do_get
像框  1121www      2       油普框16"      2006-06-19 00:00:00.000
像框  111211sdas   3       油普框16"      2006-06-19 00:00:00.000
像框  111211sa     2       油普框24"      2006-06-19 00:00:00.000
像框  11121www     2       油普框20"      2006-06-19 00:00:00.000
像框  0001     2       油普框16"       2006-06-19 00:00:00.000
礼品  0002     2   水晶之恋     NULL      2006-06-19 00:00:00.000
其他  0002     2    爱之星       NULL      2006-06-19 00:00:00.000
像框  0002     4       油普框16"        2006-06-19 00:00:00.000
像框  0002     4       油普框24"      2006-06-19 00:00:00.000
如何把item_size="油普框16"的数量加起来???//

解决方案 »

  1.   

    select a.item_name,sum(a.item_num) as item_num
      from cust_item a join customer b
    on a.custdo_id=b.custdo_id and b.cust_do_get='06-06-19' and a.item_type<>'冲印'
    group by a.item_name
      

  2.   

    select a.item_name,sum(a.item_num) as item_num
      from cust_item a join customer b
    on a.custdo_id=b.custdo_id and b.cust_do_get='06-06-19' and a.item_type<>'冲印'
    group by a.item_name,a.item_type order by a.item_type
      

  3.   

    select a.item_type,a.custdo_id,a.item_num,a.item_name,a.item_size,b.cust_do_get
    sum(a.item_num) over (partition by a.item_size)  from cust_item a join customer b
    on a.custdo_id=b.custdo_id and b.cust_do_get='06-06-19' and a.item_type<>'冲印'
      

  4.   

    to:兵芝麻
    执行语句后报以下错误
    服务器: 消息 170,级别 15,状态 1,行 2
    第 2 行: 'a' 附近有语法错误。