0
これは私が現在ピボットテーブルは2回ですか?
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
おかげ
"Breed"は "月"ではなく、 "Hugo"と "Lab"の間に明確な関係はありません。あなたは別のテーブルにすべての品種を表示するつもりですか? –