可能重复:
带有 3 个表的数据透视表
编辑:对不起,我的一列错了
我有以下表格:
_______________________________________
| ItemID | ItemName | ItemDescription |
|________|__________|_________________|
| 1 | Alice | Foo |
|________|__________|_________________|
| 2 | Bob | Bar |
|________|__________|_________________|
________________________
| LinkID | LinkAddress |
|________|_____________|
| 1 | www.c.com |
|________|_____________|
| 2 | www.b.com |
|________|_____________|
| 3 | www.a.com |
|________|_____________|
________________________________________
| AssocID | ItemID | LinkID | LinkType |
|_________|________|________|__________|
| 1 | 1 | 3 | Youtube |
|_________|________|________|__________|
| 2 | 2 | 2 | Facebook |
|_________|________|________|__________|
| 3 | 2 | 1 | Twitter |
|_________|________|________|__________|
我正在尝试获取一个 SQL 查询来创建这样的结果:
__________________________________________________________________
| ItemName | ItemDescription | Youtube | Facebook | Twitter |
|__________|_________________|___________|___________|___________|
| Alice | Foo | NULL | NULL | www.a.com |
|__________|_________________|___________|___________|___________|
| Bob | Bar | www.c.com | www.b.com | NULL |
|__________|_________________|___________|___________|___________|
这可能吗?