0

我在 redshift sql server 中有我的数据,例如:

MatchId TeamId  Teamname  Home/away  Teamstats  statsvalue
1          101     a          home      yards      0
1          101     a          home      firstdown  1
1          101     a          home      points     2
1          101     a          home      completion 4
1          202     b          away      sacks      3
1          202     b          away      penalties  5
1          202     b          away      yards      6
1          202     b          away      points     7

我希望数据如下:

MatchId TeamId  Teamname  Home/away  yards  firstdown points completion sacks penalties 
1          101     a          home     0       1        2        4        3       5
1          202     b          away     6       null     7         null    null    null
4

1 回答 1

1

然后你需要一个pivot

Select *
from yourtable
pivot (max(statsvalue) for teamstats in 
     (yards, firstdown, points, completion, sacks, penalties) 
) p 
于 2013-10-10T10:11:12.190 回答