-1
我有一个表,ID
并不是唯一的一行。每个ID
最多可以有三行。每个ID的SQL数据透视表
ID | Name | Quantity
----------------------------------------------
1 | apple | 1
1 | orange | NULL
1 | mango | 3
2 | banana | 5
2 | strawberries | 2
3 | kiwi | NULL
3 | lime | 3
3 | grape | 7
我想要一个查询,得到这个结果表:
| ID | Fruit 1 | Fruit 1 Amount | Fruit 2 | Fruit 2 Amount | Fruit 3 | Fruit 3 Amount
------------------------------------------------------------------------------------------------------------------------------------
| 1 | apple | 1 | orange | NULL | mango | 3
| 2 | banana | 5 | strawberries | 2 | NULL | NULL
| 3 | kiwi | NULL | lime | 3 | grape | 7
我想每个ID
的[高效行转换为列在SQL Server](http://stackoverflow.com/questions/15745042/efficiently-convert-rows-to-columns-in-sql-server) –
可能的复制@ TabAlleman在提到的问题中的结果表不是按ID完成的,我想为每个ID编号的行 – Wafae
您可以参考此问题http://stackoverflow.com/questions/15931607/convert-rows-to-columns-using- pivot-in-sql-server –