为什么我的月号重复

时间:2016-08-27 17:23:01

标签: sql tsql reporting-services count

我不明白,为什么此查询的结果会显示具有不同计数总数的重复月份:

 [![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

1 个答案:

答案 0 :(得分:2)

源表的大部分可能都有type列。

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