由于您使用的是SQL Server 2008+,因此您可以使用CROSS APPLY将列中的数据反转为行。
您可以使用VALUES子句与CROSS APPLY:
select distinct t.country,
c.year,
c.totalvolumn
from yourtable t
cross apply
(
values
('2007', 2007),
('2008', 2008),
('2009', 2009)
) c(year, TotalVolumn)
order by t.country, c.year;
见SQL Fiddle with Demo
或者你可以使用UNION ALL与CROSS APPLY:
select distinct t.country,
c.year,
c.totalvolumn
from yourtable t
cross apply
(
select '2007', 2007 union all
select '2008', 2008 union all
select '2009', 2009
) c(year, TotalVolumn)
order by t.country, c.year;
见SQL Fiddle with Demo。
这也可以使用UNION查询写着:
select country, '2007' year, 2007 totalVolumn
from yourtable
union
select country, '2008' year, 2008 totalVolumn
from yourtable
union
select country, '2009' year, 2009 totalVolumn
from yourtable
order by country, year;
见SQL Fiddle with Demo
可以发布更多详情请,但在()在读入数据透视先验货() – RoughPlace