4

查询一:

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

//------------------------------------------------两列中的结果
1 5
2 6
3 7
4 8

4

1 回答 1

5
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
于 2012-11-27T07:09:58.833 回答