我想通过使用SQL语句转换下表:
**Itemcode** | **Number** | **Description**
001 | 1 | blue
001 | 2 | M
002 | 1 | yellow
002 | 3 | Nike
003 | 1 | blue
003 | 2 | L
003 | 3 | Adidas
进入
Itemcode | 1 | 2 | 3
001 | blue | M |
002 | yellow | | Nike
003 | blue | L | Adidas
我在声明中尝试使用Pivot,但是没有用。谁能帮助我?
答案 0 :(得分:1)
您可以使用aggregation
:
select code,
max(case when number = 1 then Description end) as one,
max(case when number = 2 then Description end) as two,
max(case when number = 3 then Description end) as three
from table t
group by code;