Skip to content

Instantly share code, notes, and snippets.

@QuantVI
Created July 23, 2019 23:48
Show Gist options
  • Save QuantVI/1aa51ba19f2bc2f962b45c601e67aac7 to your computer and use it in GitHub Desktop.
Save QuantVI/1aa51ba19f2bc2f962b45c601e67aac7 to your computer and use it in GitHub Desktop.
HP Vertica SQL query using the OVER window function combined with a relative date range.
SELECT
day,
clicks,
SUM(clicks) OVER (order by day range between '7 days' preceding and current row) accumulated_clicks
FROM
datamart.fact_network_stats_daily
WHERE
network_id = 72
AND affiliate_country_code = 'FR'
AND banner_currency_id = 1
AND YEAR(day) = 2014
ORDER BY
day
LIMIT 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment