有表   a(item,qty,flag),如何查询得如下结果   
  ----------------------------------------------------------------   
  item  totala   totalb   totalc   
  ----------------------------------------------------------   
  其中totala为flag='1' qty的和   
  其中totalb为flag='2' qty的和   
  其中totalc为flag='3' qty的和
  item 为三个的并集,如果哪个存在可以用0填充

解决方案 »

  1.   

    decode +  group by 
      

  2.   

    错了,item 应为三个(不同的flag)的并集,如果相应的不存在可以在 相应的TOTAL 列填充0
      

  3.   

    select item,
           decode(flag, 1, sum(qty), null) totala,
           decode(flag, 2, sum(qty), null) totalb,
           decode(flag, 3, sum(qty), null) totalc
      from a
      

  4.   

    有表  a(item,qty,startdate,enddate),如何查询得如下结果  
      ----------------------------------------------------------------  
      item  totala  totalb  totalc  
      ---------------------------------------------------------- 
    sysdate为当前日期 
      其中totala为 startdate<sysdate and enddate<sysdate qty的和  
      其中totalb为 startdate<sysdate and enddate>sysdate qty的和  
      其中totalc为 startdate>sysdate and enddate>sysdate qty的和 
      item 为三个(不同条件)的并集,如果相应的不存在可以在 相应的TOTAL 列填充0
      

  5.   

    decode 能用日期类型的参数比较吗
      

  6.   

    decode  只能做相等的比较呀,还有其他的方法吗,谢