本文介绍了在两列中合并两个SQL查询的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查询1:
SELECT COUNT (A.EMPNO) AS [PRESENT]
FROM ERPDATA.NIITESS.DBO.ZEMP_MASXST_WEB_AL A INNER
JOIN PPA_EVENTWISEEMPLOYEEMASTER B ON
(CASE B.VC_BA WHEN '%' THEN LTRIM(RTRIM(A.PDIBUSHORT)) ELSE B.VC_BA END) = LTRIM(RTRIM(A.PDIBUSHORT))
AND (CASE B.VC_PA WHEN '%' THEN A.PA ELSE B.VC_PA END) = A.PA
WHERE A.STATUS = 3
AND A.EMPNO IN (SELECT VC_EMPCODE FROM ERPDATA.NIITESS.DBO.ADA_MXEASTER WHERE IN_ATTENDANCE_STATUS = 1 AND CH_ACTIVE = 'Y' AND VC_EMPCODE <> '')
GROUP BY B.IN_EVENTID
查询2:
SELECT COUNT (A.EMPNO) AS [TOTAL]
FROM ERPDATA.NIITESS.DBO.ZEMP_MASXST_WEB_AL A INNER
JOIN PPA_EVENTWISEEMPLOYEEMASTER B ON
(CASE B.VC_BA WHEN '%' THEN LTRIM(RTRIM(A.PDIBUSHORT)) ELSE B.VC_BA END) = LTRIM(RTRIM(A.PDIBUSHORT))
AND (CASE B.VC_PA WHEN '%' THEN A.PA ELSE B.VC_PA END) = A.PA
WHERE A.STATUS = 3
我想将两个结果合并为两列,而缺少的列=查询2-查询1以加快处理速度.我该怎么做?示例:
我有两个结果:
//----------------------------------------查询:1
1
2
3
4
//--------------------------------------查询:2
4
5
6
8
//------------------------------------ OUTCOME AS分为两列
1 5
2 6
3 7
4 8
I want to merge the two results into two columns with an absent column = query 2 - query 1 to process speed faster. How can i do it?EXAMPLE :
I HAVE TWO RESULT :
//----------------------------------------QUERY : 1
1
2
3
4
//--------------------------------------QUERY : 2
4
5
6
8
//------------------------------------OUTCOME AS in two columns
1 5
2 6
3 7
4 8
推荐答案
Select a.C1-b.C2 as Res
from
(
Select Count(*) as C1 from Users
Group by Name
) a
join
(
Select Count(*) as C2 from User2
Group by Name
) b ON 1=1 -- or desired condition if existing
这篇关于在两列中合并两个SQL查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!