表结构:
seq,name,type,money。seq是主键,不重复
其他可以重复。即,一个name下,可以有多条相同的type记录。
type一共有5种=============================================要实现的是
查询出每一个name下,不同type的money和。name  type1  type2  type3  type4 type5谢谢!

解决方案 »

  1.   

    select name,sum(decode(type,type1,money,0)) type1,
           sum(decode(type,type2,money,0)) type2,
           sum(decode(type,type3,money,0)) type3,
           sum(decode(type,type4,money,0)) type4,
           sum(decode(type,type5,money,0)) type5,
    from tablename
    group by name
      

  2.   

    谢谢,我在toad里执行,提示:ORA-00923: FROM keyword not found where expecte
      

  3.   

    select name,sum(decode(type,type1,money,0)) type1,
      sum(decode(type,type2,money,0)) type2,
      sum(decode(type,type3,money,0)) type3,
      sum(decode(type,type4,money,0)) type4,
      sum(decode(type,type5,money,0)) type5  --上面的这里多了个,
    from tablename
    group by name
      

  4.   


    我试了,这样也是出错的。下面是我的select english_vessel_m,
    sum(decode(BUSINESS_C,'SD',AMOUNT_BILL_N,0))'SD',
    sum(decode(BUSINESS_C,'SL',AMOUNT_BILL_N,0))'SL',
    sum(decode(BUSINESS_C,'SE',AMOUNT_BILL_N,0))'SE',
    sum(decode(BUSINESS_C,'PO',AMOUNT_BILL_N,0))'PO',
    sum(decode(BUSINESS_C,'LH',AMOUNT_BILL_N,0))'LH',
    sum(decode(BUSINESS_C,'DD',AMOUNT_BILL_N,0))'DD',
    sum(decode(BUSINESS_C,'VC',AMOUNT_BILL_N,0))'VC'
    from fee_bill
    group by english_vessel_m
      

  5.   

    --老大,取别名哪有这样的啊 as SD \ "SD" \SD
    select english_vessel_m,
    sum(decode(BUSINESS_C,'SD',AMOUNT_BILL_N,0))  SD,
    sum(decode(BUSINESS_C,'SL',AMOUNT_BILL_N,0))  SL,
    sum(decode(BUSINESS_C,'SE',AMOUNT_BILL_N,0))  SE,
    sum(decode(BUSINESS_C,'PO',AMOUNT_BILL_N,0))  PO,
    sum(decode(BUSINESS_C,'LH',AMOUNT_BILL_N,0))  LH,
    sum(decode(BUSINESS_C,'DD',AMOUNT_BILL_N,0))  DD,
    sum(decode(BUSINESS_C,'VC',AMOUNT_BILL_N,0))  VC
    from fee_bill
    group by english_vessel_m