techdocsmith commented on code in PR #15902: URL: https://github.com/apache/druid/pull/15902#discussion_r1503377296
########## docs/querying/sql-window-functions.md: ########## @@ -214,6 +309,45 @@ GROUP BY channel, __time, delta </details> +### Example with window frames + +The following query uses a few different window frames to calculate overall activity by channel: + +```sql +SELECT + channel, + TIME_FLOOR(__time, 'PT1H') AS time_hour, + SUM(delta) AS hourly_channel_changes, + SUM(SUM(delta)) OVER cumulative AS cumulative_activity_in_channel, + SUM(SUM(delta)) OVER moving5 AS csum5, + COUNT(1) OVER moving5 AS count5 +FROM "wikipedia" +WHERE channel = '#en.wikipedia' + AND __time BETWEEN '2016-06-27' AND '2016-06-28' +GROUP BY 1, TIME_FLOOR(__time, 'PT1H') +WINDOW cumulative AS ( + PARTITION BY channel + ORDER BY TIME_FLOOR(__time, 'PT1H') + ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW + ) + , + moving5 AS ( + PARTITION BY channel + ORDER BY TIME_FLOOR(__time, 'PT1H') + ROWS BETWEEN 4 PRECEDING AND CURRENT ROW Review Comment: n is a variable. in the example query you need to specify a value -- 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]
