2017-06-15 1 views
1

列にピボットしようとしていて、エラーが発生しています。私は何が間違っているのか分からない。私は以下のコードを試しましたが、 "括弧"の下に赤い波線が続き、括弧内の最初の単語が続きます。ここに私のコードは次のとおりです。列を列に入れたり、列を列に入れたりする

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; 

答えて

2

ピボット列に集計行を回転させるためです。

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 ( 

適切な行:documentationからあなたは、集約関数(SUMCOUNTを使用する必要が

<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>; 

MAXMINなど)の場合は、FORの前に入力します。

+0

あなたのデータがどのようなものか、達成しようとしているものが何であるかわからないと、私は実際にどの機能を使用すべきかを言うことができません。 – pcdev

+0

また、[この質問](https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server)を参照してください – pcdev

+0

返信、pcdevありがとうございます。とても有難い – user2089542

関連する問題