I've a query like this in PostgreSQL:
select count(id_student) students, date_beginning_course from
data.sessions_courses
left join my_schema.students on id_session_course=id_sesion
where course_name='First course'
group by date_beginning_course
What I obtain with this query is the number of students that have attended a session of "First course" in several dates, for example:
Students Date_beginning_course
____________________________________
5 2019-06-26
1 2019-06-28
5 2019-06-30
6 2019-07-01
2 2019-07-02
I'd like to fill this table with the missing date values, and, for each missing value, assign a '0' in Students column, because there are no students for this date. Example:
Students Date_beginning_course
____________________________________
5 2019-06-26
0 2019-06-27 <--new row
1 2019-06-28
0 2019-06-29 <--new row
5 2019-06-30
6 2019-07-01
2 2019-07-02
Could you help me? Thanks! :)
calendar table
(probablygenerate-series()
) and left join to that. – Monotintgenerate_series()
to create a range of dates, as per @wildplassers answer – Spinner