2

これらは 2 つのクエリであり、複数のレコードを返します。したがって、ある結果の各行データを別の結果から減算する解決策はありますか?

クエリ1:

SELECT COUNT(*) As AbhidayNotPaidSansthan
 FROM PanjikaranMaster GROUP BY Zila

クエリ 2:

SELECT COUNT(*) as anps FROM AbhidayMaster,PanjikaranMaster
    WHERE PanjikaranMaster.OfficeRegId=AbhidayMaster.OfficeRegId AND
    AbhidayMaster.DipositDate Between ('2012-09-19') AND ('2012-09-24')
GROUP BY PanjikaranMaster.Zila
4

1 に答える 1

2

このクエリを試してみてください。問題が解決します。

SELECT ISNULL(a.cnt,0) -  ISNULL(b.cnt,0) AS CNT,a.Zila
FROM
    (SELECT Zila,COUNT(*) as cnt As AbhidayNotPaidSansthan
    FROM PanjikaranMaster GROUP BY Zila) a
    LEFT JOIN 
    (SELECT Zila,COUNT(*) as cnt FROM AbhidayMaster,PanjikaranMaster
    WHERE PanjikaranMaster.OfficeRegId=AbhidayMaster.OfficeRegId AND
    AbhidayMaster.DipositDate Between ('2012-09-19') AND ('2012-09-24')
    GROUP BY PanjikaranMaster.Zila) b 
    ON a.Zila = b.Zila

SQLFIDDLEで同様のテストを行いました

于 2012-09-25T05:52:50.297 に答える