79566987

Date: 2025-04-10 14:54:28
Score: 1
Natty:
Report link

As Hans Landa would say, "That's a Bingooooo!"

The Snowflake adapted SQL produced the exact results needed.

As a point of interest, I will be implementing this method in a much larger query with many unions, then grouping those results into one answer for a net cash flow KPI.

Thank you very much for the answer.

Here it is adapted to Snowflake.

WITH Months AS (
  SELECT YEAR(date) AS Year, MONTH(date) AS Month
  FROM Date d
  WHERE d.Date >= '2019-01-01' AND d.Date < '2020-01-01'
  GROUP BY YEAR(date), MONTH(date)
)
SELECT YEAR, MONTH, COUNT(move_out_date) AS Count
FROM Months m
LEFT OUTER JOIN Lease l ON 
  l.move_out_date >= date_from_parts(Year, Month, 1) AND 
  l.move_out_date <= last_day(date_from_parts(year, month, 1))
GROUP BY year, month
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user1911400