select /*+ USE_HASH(T, W) */ w.hospital_name,
  from (select /*+ USE_HASH(D1, E, C1) */ C1.hospital_id, 
          from mt_fee_fin D1, 
               bs_medi e, 
               mt_biz_fin C1, 
               bs_insured A1, 
               bs_corp_pres B1 
         where A1.indi_id = B1.indi_id + 0 
           
           AND A1.pers_type = :ln_pers_type 
         group by C1.hospital_id 
        union 
        select /*+ USE_HASH(A2, B2, C2) */ C2.hospital_id, 
          from bs_insured A2, 
               bs_corp_pres B2, 
               mt_biz_fin C2, 
               mt_pay_record_fin D2 
         where B2.indi_id = A2.indi_id 
             AND A2.pers_type = :ln_pers_type 
         group by C2.hospital_id) t, 
       bs_hospital w 
 where w.hospital_id = t.hospital_id 
 group by w.hospital_name在上述语句中,如何选择像w.hospital_name列一样选出 pers_type 列
谢谢

解决方案 »

  1.   

    如下:select /*+ USE_HASH(T, W) */ w.hospital_name,t.pers_type
      from (select /*+ USE_HASH(D1, E, C1) */ C1.hospital_id, 0 as pers_type
              from mt_fee_fin D1, 
                   bs_medi e, 
                   mt_biz_fin C1, 
                   bs_insured A1, 
                   bs_corp_pres B1 
             where A1.indi_id = B1.indi_id + 0 
               
               AND A1.pers_type = :ln_pers_type 
             group by C1.hospital_id 
            union 
            select /*+ USE_HASH(A2, B2, C2) */ C2.hospital_id, A2.pers_type as pers_type
              from bs_insured A2, 
                   bs_corp_pres B2, 
                   mt_biz_fin C2, 
                   mt_pay_record_fin D2 
             where B2.indi_id = A2.indi_id 
                 AND A2.pers_type = :ln_pers_type 
             group by C2.hospital_id) t, 
           bs_hospital w 
     where w.hospital_id = t.hospital_id 
     group by w.hospital_name
      

  2.   

    select  w.hospital_name,t.pers_type
      from (select  C1.hospital_id,min(a1.pers_type) as pers_type 
              from mt_fee_fin D1, 
                   bs_medi e, 
                   mt_biz_fin C1, 
                   bs_insured A1, 
                   bs_corp_pres B1 
             where A1.indi_id = B1.indi_id + 0 
               
               AND A1.pers_type = :ln_pers_type 
             group by C1.hospital_id 
            union 
            select  C2.hospital_id, min(a2.pers_type) as pers_type 
              from bs_insured A2, 
                   bs_corp_pres B2, 
                   mt_biz_fin C2, 
                   mt_pay_record_fin D2 
             where B2.indi_id = A2.indi_id 
                 AND A2.pers_type = :ln_pers_type 
             group by C2.hospital_id) t, 
           bs_hospital w 
     where w.hospital_id = t.hospital_id 
     group by w.hospital_name