2017-09-21 137 views
1

如何將兩個查詢合併爲3列? BR_SURG_SLN_POS和BR_SURG_NSLN_POS總是爲0-4,所以如果這兩列可以合併爲一列,因爲它們的值是相同的。 我想要計算下兩列(BR_SURG_SLN_POS)和計數(BR_SURG_NSLN_POS)。我嘗試使用concat來合併兩列,但它不是我想要的結果。組合計數和合並列PL/SQL

select 
br_surg_SLN_POS, 
count(BR_SURG_SLN_POS)<BR> 
from BR_SURGERY<BR> 
where BR_SURG_SLN_POS between 0 and 4<BR> 
group by 
BR_SURG_SLN_POS<BR> 
order by 
BR_SURG_SLN_POS 

select 
br_surg_NSLN_POS, 
count(BR_SURG_NSLN_POS)<BR> 
from BR_SURGERY<BR> 
where BR_SURG_NSLN_POS between 0 and 4<BR> 
group by 
BR_SURG_NSLN_POS<BR> 
order by 
BR_SURG_NSLN_POS 

與此類似: enter image description here

回答

1

試試這個

select t1.sln_value, t1.sln_cnt , t2.nsln_cnt from 
    (select 
     br_surg_SLN_POS sln_value, 
     count(BR_SURG_SLN_POS) sln_cnt 
    from BR_SURGERY 
     where BR_SURG_SLN_POS between 0 and 4<BR> 
     group by 
      BR_SURG_SLN_POS) t1, 
    (select 
      br_surg_NSLN_POS nsln_value, 
      count(BR_SURG_NSLN_POS) nsln_cnt 
     from BR_SURGERY 
     where BR_SURG_NSLN_POS between 0 and 4 
      group by 
      BR_SURG_NSLN_POS) t2 
      where t1.sln_value = t2.nsln_value 
      ; 
+0

感謝爬完拉瓦特!我看到你如何命名這些列並加入了我需要合併的列。非常好,非常感謝你! –