0

次のようなテーブルがあります: 会計年度、地域、国、オフィス 1、オフィス 2、オフィス 3、オフィス 4

オフィス 1 ~ 4 は外部キーです。

オフィス 1: 会計年度、地域、国 オフィス 2: 会計年度、地域、国 オフィス 3: 会計年度、地域、国 オフィス 4: 会計年度、地域、国

これはピボットを使用して実行できますか?

4

1 に答える 1

1

それは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
于 2009-04-27T18:01:33.900 に答える