我已经使用这些Temp表来从DIstrict分组的同一表中返回SOlved案例和待处理案例总数的总数,例如
mLatch.await();
// Launch new activity here
我已经这样做但是这不会返回正确的结果
District TotalSolvedCases TotalPendingCases
A 3 1
B 8 6
C 7 1
答案 0 :(得分:4)
您只需要一个SELECT
,使用case
表达式进行条件计数:
SELECT COUNT(case when CaseHearings.IsClosingDate = 1 then 1 end) TotalCases,
COUNT(case when CaseHearings.IsClosingDate = 0 then 1 end) TotalPedningCases,
Districts.DistrictName
FROM Cases
INNER JOIN ConcernedOffices ON ConcernedOffices.pk_ConcernedOffices_ID = Cases.fk_ConcernedOffices_Cases_ConcernedOfficeID
INNER JOIN Districts ON Districts.pk_Districts_DistrictID = ConcernedOffices.fk_Districts_ConcernedOffices_DistrictID
INNER JOIN CaseHearings ON CaseHearings.fk_Cases_CaseHearings_CaseID = Cases.pk_Cases_CaseID
GROUP BY Districts.DistrictName