我無法結合這兩個查詢,我的問題是我想如何加入這兩個查詢?我是否使用加入?我想結合這兩個查詢,因爲我正在處理某些要求。我的用例是用於顯示sdrp15返回表中是否有日期。關於我的表,連接這兩個查詢的唯一東西是state_code列和階段,這兩列是我所有表中顯示的唯一列。如何結合2個查詢?
查詢1
select a.phase,a.st_code||' - '||b.state_name AS CHG,
case when a.submission_received_dt is not null then 'Y' else 'N' end as Changes
from pcspro.sdrp15_return a,
pcspro.sdrp15_states_ready b
where a.phase = b.phase and a.st_code = b.state;
結果1:
PHASE STATE CHG
A 01 - AL Y
A 11 - DC Y
A 16 - ID Y
查詢2個
select count(cou_code) as changes, state_code
from sdrp15_submission_log sl
where state_code in (select distinct state_code from sdrp15_submission_log
where state_code = sl.state_code
and cou_code != 'All')
and qa_date is null
and phase = 'A'
group by state_code;
結果2:
CHANGES STATE_CODE
-------- -------
29 01
2 11
2 16
和我想要做的就是將它們結合起來和我預期的結果應該是:
PHASE STATE CHG CHANGES
------ ------- ------ --------
A 01 - AL Y 29
A 11 - DC Y 02
A 16 - ID Y 02
A 08 - HA Y NULL
你爲什麼希望將它們組合?你的用例是什麼?你能寫一下你的桌子嗎? –
向我們展示查詢1的樣本結果和查詢2的樣本結果,並向我們展示您想要的組合結果! – jarlh
@jarlh更新了帖子 –