例表:t1( hosname varchar2(20),hostype varhcar2(10) , cash number(12,2));
数据:(hostype数据为:区内,区外,省外,四类;数据随便列举,不代表实际意义)
   hosname         hostype        cash
   一院              区内       20000.00
   二院              区内       30000.00
   五院              省外       50000.00select sum(cash),count(1) from t1 gorup by hostype上面的情况,是只显示,存在hosttype的数据。但区外,和省内的数据,因为不存在所以没有。我现在想要结果:区内  50000.00
区外      0.00
省内      0.00
省外  50000.00如何实现?琢磨一上午了,没想出来...

解决方案 »

  1.   

    with t1 as (
    select '一院' hosname,'区内' hostype,20000.00 cash from dual  union all
    select '二院' hosname,'区内' hostype,30000.00 cash from dual  union all
    select '五院' hosname,'省外' hostype,50000.00 cash from dual 

    select  '区内',sum(decode(t1.hostype,'区内',cash,0)) sum1 from t1  union all
    select  '区外',sum(decode(t1.hostype,'区外',cash,0)) from t1  union all
    select  '省外',sum(decode(t1.hostype,'省外',cash,0)) from t1  union all
    select  '省内',sum(decode(t1.hostype,'省内',cash,0)) from t1------
    1 区内 50000
    2 区外 0
    3 省外 50000
    4 省内 0
      

  2.   


    这个太具有针对性了。需要用group by 的。 是需要按定点做的统计信息. 而且要显示的数据列不只这几个。
    只是出于特殊原因的考虑,不能把信息在这里提供完全...
      

  3.   

    测试数据:CREATE TABLE T30
    (
        hosname VARCHAR2(20),
        hostype VARCHAR2(20),
        cash    NUMBER(10)
    );INSERT INTO T30 VALUES('一院', '区内', 20000);
    INSERT INTO T30 VALUES('二院', '区内', 30000);
    INSERT INTO T30 VALUES('五院', '省外', 50000);
    结果: