0
這是我目前顯示樞軸表兩次?
month | Breed| Hugo | Marco |
january 2017 | Lab | 4 | 5 |
february 2017 | Pug | 7 | 3 |
是否可以得到表 之後,而不是在一行中顯示的品種已經旋轉表?
month | Hugo | Marco |
january 2017 | 4 | 5 |
Breed | Lab | Pug |
SET @query ='SELECT * FROM(SELECT
petstoreemployee.employeefirstname as employeefirstname
,sum(petID.breed) as breeds
,Format(date, ''MMMM-yyyy'') as Month
,breed as breed
FROM
petID, petstoreemployee
WHERE
petID.petstoreemployeeID=petstoreemployee.petstoreemployeeID and
petID.ProjectedPrjID=1
and
(petID.date >= ''2017-01-01 00:00:00:000'' AND petID.date <=
''2017-12-31 00:00:00:000'')
group by petstoreemployee.employeefirstname, Format(date,''yyyy''), breeds
)
as d
PIVOT(
avg(breeds)
for employeefirstname
IN (' + @pet + ')
) as p'
exec sp_executesql @query
感謝
你想要的輸出沒有意義 - 「品種」不是「月」,「雨果」和「實驗室」之間沒有明顯的關係。您是否打算將所有品種顯示在單獨的表格中? –