【发布时间】:2021-07-01 02:14:35
【问题描述】:
这是我当前的表格数据:
| Godown_Column | Product_Column | Quantity |
|---|---|---|
| Godown 1 | Product 1 | 10 |
| Godown 1 | Product 2 | 20 |
| Godown 2 | Product 3 | 30 |
| Godown 3 | Product 3 | 40 |
这里,Godowns_Columns 的行数不受限制,具有不同的货仓。
如何编写 SQL 查询来获得此结果:
| Product_Col | Godown 1 | Godown 2 | Godown 3 |
|---|---|---|---|
| Product 1 | 10 | ||
| Product 2 | 20 | ||
| Product 3 | 30 | 40 |
【问题讨论】:
-
考虑使用枢轴来转换行 -> 列stackoverflow.com/questions/15931607/…
-
在网站上搜索“动态数据透视”
-
你应该展示你的尝试并解释卡在哪里。
标签: sql sql-server tsql sql-server-2012 dynamic-pivot