Created
April 19, 2023 00:21
-
-
Save aus10powell/f0313a022ecb46387a4feef2c1ba4c25 to your computer and use it in GitHub Desktop.
Transaction SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
transaction_date, | |
AVG(transaction_amount) AS rolling_avg | |
FROM ( | |
SELECT | |
DATE_TRUNC('day', transaction_time) AS transaction_date, | |
SUM(transaction_amount) AS transaction_amount | |
FROM | |
transactions | |
WHERE | |
DATE_TRUNC('day', transaction_time) BETWEEN '2021-01-29' AND '2021-01-31' | |
GROUP BY | |
DATE_TRUNC('day', transaction_time) | |
) AS daily_totals | |
GROUP BY | |
transaction_date | |
ORDER BY | |
transaction_date; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment