【发布时间】:2015-12-21 21:38:37
【问题描述】:
我有一个问题,我试图在我的查询中使用 PIVOT,但没有任何结果。现在我有一个看起来像这样的表:
Category Month Value
A August 10
B August 19
C August 15
A September 20
B September 23
C September 25
A October 24
B October 87
C October 44
我想让这样看:
Category August September October
A 10 20 24
B 19 23 87
C 15 25 47
在我的选择中是这样的:
Select cat_name, CAST(month AS VARCHAR(20)), value from dbo.table1.
_
select * from (
select ft.categoryData as [category], CAST(fft.date AS VARCHAR(20)) as [month], tt.value as [value] from firstt ft
join secondt st on ft.id = st.id
join thirdt tt on ft.id = tt.type_id
join fourtht fft on ft.id = fft.category_id
where ft.date between '2015-07-01' and '2015-09-01' and ft.country = 'EUR'
group by fft.date, ft.categoryData, tt.value
) as t
PIVOT (
max(value)
for [date] in ([jul], [aug], [sept])
) as pvt
【问题讨论】:
标签: sql sql-server pivot