2016-08-27 89 views
0

我不明白,爲什麼這個查詢顯示的結果複製一個月sumbmission的不同計數:爲什麼我有重複的月數

[![SELECT  CAST(B.YearNum as varchar(10))+ ' Submitted' as Type, 
       1 as OrderNum, 
       COUNT(ControlNo) Count, 
       b.YearNum, b.MonthNum 
    FROM  tblCalendar b 
        LEFT JOIN ClearanceReportMetrics a ON b.MonthNum = MONTH(a.EffectiveDate) AND b.YearNum=YEAR(a.EffectiveDate) 
        AND CompanyLine = 'Plaza Insurance Company' AND Underwriter <> 'Batcheller, Jerry' 
    WHERE  YEAR(EffectiveDate) IN (2016, 2015,2014) 
    GROUP BY b.YearNum, b.MonthNum, Type 
    order by b.YearNum, b.MonthNum][1]][1] 

enter image description here

回答

2

最有可能在源表具有type列。

select year + 1 as type, count(*) 
from (
     values 
     (1, 2014, 1) 
     , (2, 2014, 2) 
    ) t (id,year, type) 
group by year, type 
+0

OMG!你很對!我怎麼都注意不到! SERG,非常感謝你!!!! – Oleg

相關問題