当我尝试执行下面的查询时,出现错误
关键字“convert”附近的语法不正确
而且我不确定我在哪里犯了错误。qty 字段的数据类型是 nchar,所以我使用转换函数来查找总计。
select column_date, [red] as red, [blue] as blue, [green] as green, [yellow] as yellow
from
(select * from table1) as t1
pivot
(
sum(convert(int,qty))
For color in
([red], [blue], [green], [yellow])
) as SumofQuantityforeachcolor
这是桌子
column_date | color | qty | supplier
1 June 2012 | red | 2 | XY
1 June 2012 | red | 1 | AB
1 June 2012 | blue | 4 | CD
1 June 2012 | blue | 1 | XY
2 June 2012 | yellow| 13 | CD
2 June 2012 | green | 45 | CD
2 June 2012 | blue | 32 | AB
2 June 2012 | red | 37 | XY
2 June 2012 | red | 2 | XY
2 June 2012 | red | 1 | AB
2 June 2012 | blue | 4 | CD
3 June 2012 | red | 1 | AB
3 June 2012 | blue | 4 | CD
3 June 2012 | blue | 1 | XY
3 June 2012 | yellow| 13 | CD
3 June 2012 | green | 45 | CD
3 June 2012 | blue | 32 | AB
等等...