试试这个
select sum(case when 商品名称 like '%笔%' then 卖出价 end) as 笔,
       sum(case when 商品名称 ='毛衣' then 卖出价 end) as 毛衣
from 商品进货表

解决方案 »

  1.   

    我想是因为case不支持like语句吧!
    这样试试:select sum(case 商品名称 when 圆珠笔 then 卖出价 when 铅笔 then 卖出价 when 毛笔 then 卖出价) as 笔,
           sum(case 商品名称 when '毛衣' then 卖出价) as 毛衣
    from 商品进货表就是分别列出来:-)
      

  2.   

    对不住,举例子的时候粗心大意了.见谅
    select sum(case 商品名称 when like '%笔%' then 卖出价 else 0 end) as 笔,
           sum(case 商品名称 when '毛衣' then 卖出价else 0 end) as 毛衣
    from 商品进货表好像就是不支持like,怎么办?
    因为商品名称不固定的.必须用like
      

  3.   

    case支持like !
    select sum(case when 商品名称 like '%笔%' then 卖出价 else 0 end) as 笔,
           sum(case when 商品名称 ='毛衣' then 卖出价 else 0 end) as 毛衣
    from 商品进货表
      

  4.   

    select sum(case 商品名称 when charindex('笔',商品名称,1)>=1 then 卖出价 else 0 end) as 笔,
           sum(case 商品名称 when '毛衣' then 卖出价else 0 end) as 毛衣
    from 商品进货表
      

  5.   

    说支持like 啊,楼主!那你怎么回事??!我不理了,嘻嘻:-)
      

  6.   

    错了啊,赫赫
    select sum(case  when charindex('笔',商品名称,1)>=1 then 卖出价 else 0 end) as 笔,
           sum(case  when 商品名称='毛衣' then 卖出价else 0 end) as 毛衣
    from 商品进货表
      

  7.   

    case的搜索方式是步支持like 
    用简单方式可以。
      

  8.   

    嗯,应该放到When后面组成查询条件
      

  9.   

    55555~~~~~~~~555555555~~~~~~~~~~~~~~~~
    我要举报Yang_在光天化日之下竟然骗我嘻嘻:-)
      

  10.   

    to:CoolSlob()
      怎么骗你了!