将列旋转成行,反之亦然
Pivoting columns into rows and vice versa
我正在尝试转换为列,但我一直 运行 出错。我不知道我做错了什么。我尝试了下面的代码,但我一直在 "FOR" 和括号中的第一个单词下面看到红色的波浪线。这是我的代码:
select d.City,d.Geographic_Region_Name, d.Site_Type
from Site_Profile as d
pivot
(City for Geographic_Region_Name in (City,Geographic_Region_Name,site_type) as pivotable;
Pivot 用于将聚合行转换为列。来自 documentation:
SELECT <non-pivoted column>,
[first pivoted column] AS <column name>,
[second pivoted column] AS <column name>,
...
[last pivoted column] AS <column name> FROM
(<SELECT query that produces the data>)
AS <alias for the source query> PIVOT (
相关行:
<aggregation function>(<column being aggregated>)
其余
FOR [<column that contains the values that will become column headers>]
IN ( [first pivoted column], [second pivoted column],
... [last pivoted column]) ) AS <alias for the pivot table>
<optional ORDER BY clause>;
您需要在 FOR
.[=20 之前使用聚合函数(SUM
、COUNT
、MAX
、MIN
等) =]
我正在尝试转换为列,但我一直 运行 出错。我不知道我做错了什么。我尝试了下面的代码,但我一直在 "FOR" 和括号中的第一个单词下面看到红色的波浪线。这是我的代码:
select d.City,d.Geographic_Region_Name, d.Site_Type
from Site_Profile as d
pivot
(City for Geographic_Region_Name in (City,Geographic_Region_Name,site_type) as pivotable;
Pivot 用于将聚合行转换为列。来自 documentation:
SELECT <non-pivoted column>,
[first pivoted column] AS <column name>,
[second pivoted column] AS <column name>,
...
[last pivoted column] AS <column name> FROM
(<SELECT query that produces the data>)
AS <alias for the source query> PIVOT (
相关行:
<aggregation function>(<column being aggregated>)
其余
FOR [<column that contains the values that will become column headers>]
IN ( [first pivoted column], [second pivoted column],
... [last pivoted column]) ) AS <alias for the pivot table>
<optional ORDER BY clause>;
您需要在 FOR
.[=20 之前使用聚合函数(SUM
、COUNT
、MAX
、MIN
等) =]