自己慢慢写吧,就是麻烦,你需要有耐心。
但我觉得一条sql可以搞定,但我这没有oracle的任何玩意,唉,自己动手吧!

解决方案 »

  1.   

    解决办法:将地市和面值做成一张虚拟表(结果集),然后按照地市,面值,类型,厂家取出卡数量并与虚拟表关联(外连接)。比较麻烦:(
    select v1.cityname,v1.valuename,v2.cardcount,v3.cardamount……
    from 
    (select a.citycode,a.cityname,b.valuecode,b.valuename from 城市表 a, 面值表 b) v1,
    (select citycode,valuecode,sum(cardamount) cardamount
    from 卡库存表
    where cardtypecode=卡类型1
    and factorycode = 生产厂家1
    )v2,
    (select citycode,valuecode,sum(cardamount) ardamount
    from 卡库存表
    where cardtypecode=卡类型1
    and factorycode = 生产厂家2
    )v3……
    where 
        v2.citycode = v1.citycode(+)
    and v3.citycode = v1.citycode(+)
    ……
    and v2.valuecode = v1.valuecode(+)
        v3.valuecode = v1.valuecode(+)
    ……