0
我的查詢即時將數據分解12個月,但列'Submitted - New Business'
來自另一個表。它有沒有可能按月分解?按月分選select語句
SELECT 'Eldred, Rod' AS Underwriter,
SUM(CASE WHEN Underwriter = 'Eldred, Rod' THEN UWReportFee ELSE 0 END) as 'UW ReportFee',
(SUM(CASE WHEN Underwriter = 'Eldred, Rod' THEN Fees ELSE 0 END)) - SUM(CASE WHEN Underwriter = 'Eldred, Rod' THEN UWReportFee ELSE 0 END) as 'Taxes & Surcharges',
COUNT(CASE WHEN Underwriter = 'Eldred, Rod' AND PolicyType = 'New Business' THEN QuoteControlNum END) as 'Submitted - New Business',
/*SubQuery*/
(
SELECT COUNT(CASE WHEN Underwriter = 'Eldred, Rod' AND Type = 'New Business' THEN ControlNo END)
FROM tblCalendar b
LEFT JOIN ClearanceReportMetrics a ON b.MonthNum=Month(a.EffectiveDate)
AND b.YearNum = YEAR(a.EffectiveDate) AND CompanyLine = 'Arch Insurance Company' AND YEAR(EffectiveDate)=2016
) as 'Submitted - New Business' ,
/* End of SubQuery*/
b.MonthNum,
b.YearNum
FROM tblCalendar b
LEFT JOIN ProductionReportMetrics a ON b.MonthNum=Month(a.EffectiveDate)
AND b.YearNum = YEAR(a.EffectiveDate) AND CompanyLine = 'Arch Insurance Company' AND YEAR(EffectiveDate)=2016
--AND a.Underwriter ='Eldred, Rod'
WHERE b.YearNum = 2016
GROUP BY --a.Underwriter,
b.MonthName,
b.MonthNum,
b.YearNum
,你可以在PIC看到,每個月都有相同的價值,是任何機會,以某種方式打破它沒有全光照JOIN
?
使用相關子查詢到從外到您的一個月(a.effectivedate)加入b.month?但你需要以不同的方式別名內部查詢B表。 – xQbert
謝謝。但是你有什麼好的例子嗎? – Oleg
你需要加入2個grpouped查詢或分組後交叉應用。加入有什麼問題? – Serg