How to combine result of below three queries?
IF (select count(TTMPRCNO) from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='ICICI Bank' and type='OFFLINE' and LotNo=5518)>0
(select count(TTMPRCNO) as 'ICICI_OFF_CNT',(cast(SUM(cast(APE_Mn as float)) as decimal(15,2))) AS 'API_MIN',(cast(round(SUM(cast(Premium_Mn as float)),2) as decimal(15,2)))
as 'PRI_MIN' from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='ICICI Bank' and type='OFFLINE' and LotNo=5518)
ELSE
(select '0' as 'ICICI_OFF_CNT', '0.00' as 'API_MIN' ,'0.00' as 'PRI_MIN')
IF(select count(TTMPRCNO) from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='Non ICICI Bank' and type='OFFLINE' and LotNo=5518)>0
select count(TTMPRCNO) as 'NON_ICICI_OFF_CNT',(cast(SUM(cast(APE_Mn as float)) as decimal(15,2))) AS 'NON_API_MIN',(cast(round(SUM(cast(Premium_Mn as float)),2) as decimal(15,2)))
as 'NON_PRI_MIN' from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='Non ICICI Bank' and type='OFFLINE' and LotNo=5518
ELSE
select '0' as 'ICICI_OFF_CNT', '0.00' as 'API_MIN' ,'0.00' as 'PRI_MIN'
IF(select count(TTMPRCNO) from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='SCBK' and type='OFFLINE' and LotNo=5518)>0
select count(TTMPRCNO) as 'SCBK_OFF_CNT',(cast(SUM(cast(APE_Mn as float)) as decimal(15,2))) AS 'SCBK_API_MIN',(cast(round(SUM(cast(Premium_Mn as float)),2) as decimal(15,2)))
as 'SCBK_PRI_MIN' from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='SCBK' and type='OFFLINE' and LotNo=5518
ELSE
select '0' as 'ICICI_OFF_CNT', '0.00' as 'API_MIN' ,'0.00' as 'PRI_MIN'
答案 0 :(得分:0)
它看起来像SQL Server,如果是这种情况,应该这样做:
Select count(TTMPRCNO) as 'ICICI_OFF_CNT'
, (cast(SUM(cast(APE_Mn as float)) as decimal(15,2))) AS 'API_MIN'
, (cast(round(SUM(cast(Premium_Mn as float)),2) as decimal(15,2))) as 'PRI_MIN'
From Real_Time_Login_Query_Remark
where Ibank_NonIbank_SCB ='ICICI Bank' and type='OFFLINE' and LotNo=5518)
UNION ALL
select '0' as 'ICICI_OFF_CNT', '0.00' as 'API_MIN' ,'0.00' as 'PRI_MIN'
where not exists (select 1 from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='ICICI Bank' and type='OFFLINE' and LotNo=5518)
UNION ALL
select count(TTMPRCNO) as 'NON_ICICI_OFF_CNT'
,(cast(SUM(cast(APE_Mn as float)) as decimal(15,2))) AS 'NON_API_MIN'
,(cast(round(SUM(cast(Premium_Mn as float)),2) as decimal(15,2))) as 'NON_PRI_MIN'
from Real_Time_Login_Query_Remark
where Ibank_NonIbank_SCB ='Non ICICI Bank' and type='OFFLINE' and LotNo=5518
UNION ALL
select '0' as 'ICICI_OFF_CNT', '0.00' as 'API_MIN' ,'0.00' as 'PRI_MIN'
where not exists (select 1 from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='ICICI Bank' and type='OFFLINE' and LotNo=5518)
UNION ALL
select count(TTMPRCNO) as 'NON_ICICI_OFF_CNT'
,(cast(SUM(cast(APE_Mn as float)) as decimal(15,2))) AS 'NON_API_MIN'
,(cast(round(SUM(cast(Premium_Mn as float)),2) as decimal(15,2))) as 'NON_PRI_MIN'
from Real_Time_Login_Query_Remark
where Ibank_NonIbank_SCB ='Non ICICI Bank' and type='OFFLINE' and LotNo=5518
UNION ALL
select '0' as 'ICICI_OFF_CNT', '0.00' as 'API_MIN' ,'0.00' as 'PRI_MIN'
where not exists (select count(TTMPRCNO) from Real_Time_Login_Query_Remark where Ibank_NonIbank_SCB ='Non ICICI Bank' and type='OFFLINE' and LotNo=5518)
第一个查询是您的常规查询。第二个查询是你的ifse条件下不存在的Else Select。 选择3和4以及选择5和6也是如此。