PIVOT ( pivot_spec )
[ WITH with_spec [,...] ]
[AS] derived_table_name [ ( cname [,...] ) ]
Syntax Elements
-
pivot_spec
-
aggr_fn_spec [,...] FOR for_spec
-
with_spec
-
aggr_fn ( { cname [,...] | * } ) [AS] aggr_alias
-
derived_table_name
- The table name specified for the resultant pivoted table.
-
cname
- A column name.
-
aggr_fn_spec
-
aggr_fn ( cname ) [ [AS] pvt_aggr_alias ]
-
for_spec
-
{ cname IN ( expr_spec_1 [,...] ) |
( cname [,...] ) IN ( expr_spec_2 [,...] ) |
cname IN ( subquery )
}
-
aggr_fn
- An aggregate function that supports a single argument.
- *
- Option to include all the Pivot columns without specifying columns explicitly.
-
aggr_alias
- Name of the aggregate result column.
-
pvt_aggr_alias
- An alias name specified for the Aggregate function.
-
expr_spec_1
-
expr [ [AS] expr_alias_name ]
-
expr_spec_2
-
( expr [,...] ) [ [AS] expr_alias_name ]
-
expr
- An expression or a column value.
-
expr_alias_name
- An alias name specified for the values/expressions specified in the IN list.