Created
November 24, 2021 17:44
-
-
Save Mr--John-Doe/9392604c0def94112668bb2c0f5c29d2 to your computer and use it in GitHub Desktop.
The Procedural Thinking - Cursor For Loops
This file contains 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
FOR date IN list_of_dates | |
LOOP | |
INSERT INTO final_table(date, revenue_mtd) | |
SELECT @date as date, sum(revenue) as revenue_mtd | |
FROM sales | |
WHERE sales.dt between date_trunc('month',@date) and @date; | |
END LOOP; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment