ektravel commented on code in PR #15669:
URL: https://github.com/apache/druid/pull/15669#discussion_r1450638934


##########
docs/querying/sql.md:
##########
@@ -85,6 +87,121 @@ FROM clause, metadata tables are not considered 
datasources. They exist only in
 For more information about table, lookup, query, and join datasources, refer 
to the [Datasources](datasource.md)
 documentation.
 
+## PIVOT
+
+:::info
+The PIVOT operator is an [experimental 
feature](../development/experimental-features.md).
+:::
+
+The PIVOT operator carries out an aggregation and transforms rows into columns 
in the output.
+
+The following is the general syntax for the PIVOT operator. Note that the 
PIVOT operator is enclosed in parentheses and forms part of the FORM clause of 
the query.
+
+```sql
+PIVOT (aggregation_function(column_to_aggregate)
+  FOR [column_with_values_to_pivot]
+  IN ( [pivoted_column1], [pivoted_column2] ...)
+)
+```
+
+PIVOT syntax parameters:
+
+* `aggregation_function`: An aggregation function such as SUM, COUNT, MIN, 
MAX, or AVG.
+* `column_to_aggregate`: The source column to be aggregated.
+* `column_with_values_to_pivot`: The column that contains values for the 
pivoted column names.
+* `pivoted_columnN`: The list of values to pivot into headings in the output.
+
+The following example demonstrates how to transform `cityName` values into 
column headings `a_sum_deleted` and `b_sum_deleted`:
+
+```sql
+SELECT user, a_sum_deleted, b_sum_deleted 
+FROM "wikipedia"
+PIVOT (SUM(deleted) AS "sum_deleted" FOR "cityName" IN ('Buenos Aires' AS b, 
'Abu Dhabi' AS a))
+WHERE b_sum_deleted IS NOT NULL OR a_sum_deleted IS NOT NULL
+LIMIT 15
+```
+
+<details>
+<summary> View results </summary>
+
+| `user` | `a_sum_deleted` | `b_sum_deleted`|
+| ------ | --------------- | -------------- | 
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|190.123.145.147|      null|   0|
+|181.230.118.178|      null|   16|
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|190.192.179.192|      null|   0|
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|181.230.118.178|      null|   0|
+|86.98.150.78| 0|      null|
+
+</details>
+
+## UNPIVOT
+
+:::info
+The UNPIVOT operator is an [experimental 
feature](../development/experimental-features.md).
+:::
+
+The UNPIVOT operator transforms existing column values into rows.
+Note that UNPIVOT isn't the exact reverse operation of PIVOT. The PIVOT 
operator carries out an aggregation and merges rows as needed. UNPIVOT doesn't 
reproduce the original rows that have been merged.
+
+The following is the general syntax for the UNPIVOT operator. Note that the 
UNPIVOT operator is enclosed in parentheses and forms part of the FORM clause 
of the query.

Review Comment:
   Good catch. Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to