澄清SQL表

时间:2016-08-01 08:38:00

标签: sql access-vba ms-access-2010

这是我要访问的表格。

Account | col1 | col2 | col3
.............................
value 1   x1     x2     x3
value 2   x1     x2     x3

我想要做的是我希望将此表转换为此格式,如下所述,

Account | Carrier |  |
........................
value 1    col1    x1
value 1    col2    x2
value 1    col3    x3

如何使用select sql执行此操作。如果有人能帮助我解决这个问题,我真的很感激

谢谢,

1 个答案:

答案 0 :(得分:1)

为每个运营商执行SELECT。结果UNION ALL

select Account, 'col1' as carrier, col1 from tablename
union all
select Account, 'col2' as carrier, col2 from tablename
union all
select Account, 'col3' as carrier, col3 from tablename
order by Account, carrier