2012-09-24 66 views
1

我解决了查询......但现在我有这两个查询合并:如何合并两个select查询?

(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 

回答

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标准加入 - 一个明确的INNER JOIN,它的JOIN条件在那里它属于(见Bad habits to kick : using old-style JOINs了解为什么“旧式”JOIN是一个非常糟糕的主意,应该避免)。

我也改变你的日期字符串文字是语言和区域设置 - 安全 - 格式为YYYYMMDD没有破折号!)

+0

@ user1673240:请**不要**把代码样本或试样数据转换为注释 - 因为您无法对其进行格式化,所以**非常难**阅读它。相反:**通过编辑来更新**问题以提供更多信息!谢谢。 –

+0

感谢您的帮助......该问题已解决..再次我卡在另一个查询..请参阅上述更新的查询。 – azz845

+0

请任何人帮我解决这个问题....... – azz845