こんにちは、仕事で次のような手順があります
create procedure sp_CountPickupsduringYearReportA1A2
@MyYear int
AS
SELECT
MAX(a.AgencyName),
COUNT(PickupID) as YearTotal,
COUNT(PickupID)/(CASE WHEN YEAR(GETDATE()) =@myYear THEN MONTH(GETDATE()) ELSE 12 END) as MoAvg,
SUM(CASE WHEN DATEPART(month, PickupDate) = 1 THEN 1 ELSE 0 end) as Jan,
SUM(CASE WHEN DATEPART(month, PickupDate) = 2 THEN 1 ELSE 0 end) as Feb,
SUM(CASE WHEN DATEPART(month, PickupDate) = 3 THEN 1 ELSE 0 end) as Mar,
SUM(CASE WHEN DATEPART(month, PickupDate) = 4 THEN 1 ELSE 0 end) as Apr,
SUM(CASE WHEN DATEPART(month, PickupDate) = 5 THEN 1 ELSE 0 end) as May,
SUM(CASE WHEN DATEPART(month, PickupDate) = 6 THEN 1 ELSE 0 end) as Jun,
SUM(CASE WHEN DATEPART(month, PickupDate) = 7 THEN 1 ELSE 0 end) as Jul,
SUM(CASE WHEN DATEPART(month, PickupDate) = 8 THEN 1 ELSE 0 end) as Aug,
SUM(CASE WHEN DATEPART(month, PickupDate) = 9 THEN 1 ELSE 0 end) as Sep,
SUM(CASE WHEN DATEPART(month, PickupDate) = 10 THEN 1 ELSE 0 end) as Oct,
SUM(CASE WHEN DATEPART(month, PickupDate) = 11 THEN 1 ELSE 0 end) as Nov,
SUM(CASE WHEN DATEPART(month, PickupDate) = 12 THEN 1 ELSE 0 end) as Dec
FROM dbo.Pickup p join Agency a on p.agencyid = a.agencyid
where DATEPART(year, PickupDate) = @MyYear
group by a.AgencyID
order by a.AgencyID
それは完全に機能し、次のように応答します
name YearTotal MoAvg 1, 2, 3, 4, 5, 6, 7,8,9,10,11,12
test 13 1 1 1 1 1 1 1 1 1 1 1 1 1 2
各列の単純な合計の合計を次のような列に表示する必要があります
name YearTotal MoAvg 1, 2, 3, 4, 5, 6, 7,8,9,10,11,12
total 25 2 2 2 2 2 2 2 2 2 2 2 2 2 3
test 13 1 1 1 1 1 1 1 1 1 1 1 1 1 2
test 12 1 1 1 1 1 1 1 1 1 1 1 1 1 1
それを行う方法はありますか?私はこのパズルを何時間も解こうとしていますが、まだ理解できません