2012-09-24 99 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