【发布时间】:2017-01-18 15:08:19
【问题描述】:
我有以下数据库表:
| Article | Material |
|------------|-------------|
| article001 | material001 |
| article001 | material002 |
| article002 | material002 |
| article002 | material003 |
| article002 | material004 |
| article003 | material002 |
| article004 | material003 |
| article004 | material004 |
| article004 | material005 |
| article004 | material006 |
我想达到这样的结果:
| Article | Material1 | Material2 | Material3 | Material4 |
|------------|-------------|-------------|-------------|-------------|
| article001 | material001 | material002 | | |
| article002 | material002 | material003 | material004 | |
| article003 | material002 | | | |
| article004 | material003 | material004 | material005 | material006 |
我已经尝试过各种可能性(Pivot、CTE、临时表)。不幸的是,我不明白。我对 SQL 很陌生。
【问题讨论】:
-
添加你目前尝试过的查询
标签: sql-server multiple-columns rows