2016-08-27 3 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

関連する問題