我无法结合这两个查询,我的问题是我想如何加入这两个查询?我是否使用加入?我想结合这两个查询,因为我正在处理某些要求。我的用例是用于显示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更新了帖子 –