2015-09-03 30 views
0
select count(cou_code) as Changes 
from sdrp15_cosd  
where sd_code in 
(select sd_code from sdrp15_submission_log 
where QA_date is null) 

它给我的结果加入2个subquerys

变化| 629

select count(cou_code) as Complete 
from sdrp15_cosd  
where sd_code in 
(select sd_code from sdrp15_submission_log 
where QA_date is not null) 

它给我造成

完成| 210

我想有2个一个名为完成这两者的查询(上图)合并成一个查询

+0

MySQL和Oracle是两种不同的产品,略有不同版本的SQL。你在使用哪一个? – jarlh

+0

您可以添加一些样本数据(涉及所有表格)和预期结果。 – jarlh

+0

@jarlh我相信我正在使用oracle sql – chihao

回答

1

做两个条件计数(与CASE),一个用于is null的命名改一另一个用于is not null's。

select count(case when sd_code in (select sd_code from sdrp15_submission_log 
            where QA_date is null) then 1 end) as Changes, 
     count(case when sd_code in (select sd_code from sdrp15_submission_log 
            where QA_date is not null) then 1 end) as Complete 
from sdrp15_cosd 
+0

谢谢,但现在如何结合您的查询(上面)和这一个: select a.phase,a.st_code ||' - '|| b.state_name, 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 其中a.phase = b.phase和a.st_code = b.state; – chihao

+0

??????????????? – chihao

0

尝试UNION

select count(cou_code) as Changes from sdrp15_cosd where sd_code in 
(select sd_code from sdrp15_submission_log where QA_date is null) 
UNION 
select count(cou_code) as Complete from sdrp15_cosd where sd_code in 
(select sd_code from sdrp15_submission_log where QA_date is not null) 
+0

建议改进:做UNION ALL。在firts部分也选择'Complete',在第二个部分选择'Changes'。 – jarlh