1

我解决了那个查询......但现在我必须合并这两个查询:

(SELECT Zila,
COUNT(AbhidayMaster.OfficeRegId) As AbhidayPaidSansthan,
SUM(AbhidayMaster.TotalEmp) As TotalWorkerPaid
FROM PanjikaranMaster, AbhidayMaster
WHERE PanjikaranMaster.OfficeRegId=AbhidayMaster.OfficeRegId
AND AbhidayMaster.DipositDate Between ('2012-06-22') AND ('2012-09-19') GROUP BY Zila)



Select 
((SELECT count(distinct OfficeRegId) FROM PanjikaranMaster)
 -
(SELECT count(distinct OfficeRegId) FROM AbhidayMaster)) As AbhidayNotPaidSansthan
4

1 回答 1

2

怎么样:

SELECT 
   Zila, 
   COUNT(AbhidayMaster.OfficeRegId) As AbhidayPaidSansthan ,
   SUM(AbhidayMaster.TotalEmp) As TotalWorkerPaid
FROM 
   PanjikaranMaster
INNER JOIN
   AbhidayMaster ON PanjikaranMaster.OfficeRegId = AbhidayMaster.OfficeRegId
WHERE
   AbhidayMaster.DipositDate BETWEEN '20120622' AND '20120919'
GROUP BY 
   Zila

我更改了您的 JOIN 语法以使用正确的 ANSI/ISO 标准 JOIN - 一个显式INNER JOIN的 JOIN 条件就在它所属的位置(请参阅要踢的坏习惯:使用旧式 JOIN以了解为什么“旧式” JOIN 是真是个坏主意,应该避免)。

我还将您的日期字符串文字更改为语言和区域设置安全-格式为YYYYMMDD无破折号!)

于 2012-09-24T06:25:21.943 回答