【发布时间】:2017-05-25 02:56:36
【问题描述】:
select name,value from (
select name,value from
(
select 'WHB' name,count(*) value from bld_comp_prep where bld_comp_code ='WHB' and comp_code =:a_bld_user_comp and nvl(status,'S')='S' and nvl(delete_flag,'N') ='N'
union all
select 'RBC' name,count(*) value from bld_comp_prep where bld_comp_code ='RBC' and comp_code =:a_bld_user_comp and nvl(status,'S')='S' and nvl(delete_flag,'N') ='N'
union all
select 'FFP' name,count(*) value from bld_comp_prep where bld_comp_code ='FFP' and comp_code =:a_bld_user_comp and nvl(status,'S')='S' and nvl(delete_flag,'N') ='N'
union all
select 'PLC' name,count(*) value from bld_comp_prep where bld_comp_code ='PLC' and comp_code =:a_bld_user_comp and nvl(status,'S')='S' and nvl(delete_flag,'N') ='N'
union all
select 'CRY' name,count(*) value from bld_comp_prep where bld_comp_code ='CRY' and comp_code =:a_bld_user_comp and nvl(status,'S')='S' and nvl(delete_flag,'N') ='N'
union all
select 'GRC' name,count(*) value from bld_comp_prep where bld_comp_code ='GRC' and comp_code =:a_bld_user_comp and nvl(status,'S')='S' and nvl(delete_flag,'N') ='N'
)
left JOIN (
select name,value from(
select 'WHB' name, count(*) value from bld_issue_dtl dtl,bld_issue_hdr hdr,bld_comp_prep prep where prep.bld_comp_code ='WHB' and hdr.issue_code =dtl.issue_code and hdr.comp_code =dtl.comp_code and dtl.comp_bag_code =prep.comp_bag_code and dtl.comp_code =prep.comp_code and TO_DATE(hdr.issue_date,'DD-MON-YY') =TO_DATE(:P29_STOCK_DATE,'DD-MON-YY')
union all
select 'RBC' name, count(*) value from bld_issue_dtl dtl,bld_issue_hdr hdr,bld_comp_prep prep where prep.bld_comp_code ='RBC' and hdr.issue_code =dtl.issue_code and hdr.comp_code =dtl.comp_code and dtl.comp_bag_code =prep.comp_bag_code and dtl.comp_code =prep.comp_code and TO_DATE(hdr.issue_date,'DD-MON-YY') =TO_DATE(:P29_STOCK_DATE,'DD-MON-YY')
union all
select 'FFP' name, count(*) value from bld_issue_dtl dtl,bld_issue_hdr hdr,bld_comp_prep prep where prep.bld_comp_code ='FFP' and hdr.issue_code =dtl.issue_code and hdr.comp_code =dtl.comp_code and dtl.comp_bag_code =prep.comp_bag_code and dtl.comp_code =prep.comp_code and TO_DATE(hdr.issue_date,'DD-MON-YY') =TO_DATE(:P29_STOCK_DATE,'DD-MON-YY')
union all
select 'PLC' name, count(*) value from bld_issue_dtl dtl,bld_issue_hdr hdr,bld_comp_prep prep where prep.bld_comp_code ='PLC' and hdr.issue_code =dtl.issue_code and hdr.comp_code =dtl.comp_code and dtl.comp_bag_code =prep.comp_bag_code and dtl.comp_code =prep.comp_code and TO_DATE(hdr.issue_date,'DD-MON-YY') =TO_DATE(:P29_STOCK_DATE,'DD-MON-YY')
union all
select 'CRY' name, count(*) value from bld_issue_dtl dtl,bld_issue_hdr hdr,bld_comp_prep prep where prep.bld_comp_code ='CRY' and hdr.issue_code =dtl.issue_code and hdr.comp_code =dtl.comp_code and dtl.comp_bag_code =prep.comp_bag_code and dtl.comp_code =prep.comp_code and TO_DATE(hdr.issue_date,'DD-MON-YY') =TO_DATE(:P29_STOCK_DATE,'DD-MON-YY')
union all
select 'GRC' name, count(*) value from bld_issue_dtl dtl,bld_issue_hdr hdr,bld_comp_prep prep where prep.bld_comp_code ='GRC' and hdr.issue_code =dtl.issue_code and hdr.comp_code =dtl.comp_code and dtl.comp_bag_code =prep.comp_bag_code and dtl.comp_code =prep.comp_code and TO_DATE(hdr.issue_date,'DD-MON-YY') =TO_DATE(:P29_STOCK_DATE,'DD-MON-YY')
)));
【问题讨论】:
-
这不是问题。问题以字符
?结尾。而且我不知道您所说的“将这两个选择列表相互添加”是什么意思。 -
问题不清楚。您可能想查看minimal reproducible example 以构建示例并澄清您的问题。照原样,我相信这个问题很快就会结束。
-
我注意到两件事:1)您的内部查询可以只是一个带有 GROUP BY 的查询,2)您应该使用
JOIN而不是 SELECT ... FROM x, y WHERE ...修复这些之后,看看连接两个表的正确连接是否更清晰。 -
@Gary_W 我看了预编辑,圣牛。很好的编辑,让我免于心脏病发作。 :P
-
@Gary_W 抱歉,更重要的是您进行了出色的编辑,而不是其他任何事情。我目前正在检查它。