我有一张这样的表:财政年度,地区,国家,Office1,Office2,Office3,Office4
其中办公室 1-4 是外键。
我想得到这样的输出: Office 1:财政年度,地区,国家办事处 2:财政年度,地区,国家办事处 3:财政年度,地区,国家办事处 4:财政年度,地区,国家
这可以使用枢轴完成吗?
我有一张这样的表:财政年度,地区,国家,Office1,Office2,Office3,Office4
其中办公室 1-4 是外键。
我想得到这样的输出: Office 1:财政年度,地区,国家办事处 2:财政年度,地区,国家办事处 3:财政年度,地区,国家办事处 4:财政年度,地区,国家
这可以使用枢轴完成吗?
我认为这更像是 UNPIVOT:
SELECT [Fiscal Year], Region, County, OFfice
FROM
(SELECT [Fiscal Year], Region, County, OFfice1, Office2, Office3, Office4
FROM unpvt) p
UNPIVOT
(yourtable FOR Office IN
(Office1, Office2, Office3, Office4)
) AS unpvt;
但是你也可以通过一个简单的查询来做到这一点:
select [Fiscal Year], Region, County, OFfice1
from yourtable
union
select [Fiscal Year], Region, County, OFfice2
from yourtable
union
select [Fiscal Year], Region, County, OFfice3
from yourtable
union
select [Fiscal Year], Region, County, OFfice4
from yourtable