Window and CTE
Last updated
Last updated
PostgreSQL offers writing of . Common Table Expressions are useful to define temporary SQL query used in a bigger query.
For this example, let's assume we want to count the new user creation per day during the month of September. One way would be to Group by EXTRACT('day' FROM created_at)
, but days without new user will return not rows, where we want it to return zero.
In this case, using joins onto a generated series of day is the way to go. CTE makes it very simple to write and manage:
You can using window method: