Skip to content

Instantly share code, notes, and snippets.

@Mr--John-Doe
Created November 24, 2021 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mr--John-Doe/9392604c0def94112668bb2c0f5c29d2 to your computer and use it in GitHub Desktop.
Save Mr--John-Doe/9392604c0def94112668bb2c0f5c29d2 to your computer and use it in GitHub Desktop.
The Procedural Thinking - Cursor For Loops
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