SQL如何根据一个字段的值将表扩展到更多字段
例如,我有这样的事情:
ID Name Age YearQuarter Points
1 Tom 13 20131 100
1 Tom 13 20132 99
3 May 13 20133 98
我需要
ID Name Age Points20131 Points20132 Points20133
1 Tom 13 100 99 NA
3 May 13 NA NA 98
我尝试过类似的东西
SELECT ID, Name,Age, Points as 'Points20131', 'NA' as 'Points20132', 'NA' as 'Point20133'
FROM table where YearQuarter = 20131
UNION
SELECT ID, Name,Age, 'NA' as 'Points20131', Points as 'Points20132', 'NA' as 'Point20133'
FROM table where YearQuarter = 20132
UNION
SELECT ID, Name,Age, 'NA' as 'Points20131', 'NA' as 'Points20132', Points as 'Point20133'
FROM table where YearQuarter = 20133
但这会生成 2 条汤姆的记录。如
ID Name Age Points20131 Points20132 Points20133
1 Tom 13 100 NA NA
2 Tom 13 NA 99 NA
3 May 13 NA NA 98
如何解决这个问题?
谢谢