UPD removed one unessential line.
On python I use sqlite3 to work with tables. I am trying to combine data from 3 tables and count the number of rows of statistics in combination of data from the first two:
SELECT pd.d_id, pd.l_id, COUNT(*) FROM ( SELECT p.id AS l_id, d.id AS d_id FROM people p LEFT JOIN duties d ON p.project_id = d.project_id) pd LEFT JOIN stats st ON pd.l_id = st.login_id AND pd.d_id = st.duty_id GROUP BY pd.d_id, pd.l_id; At the same time, I see that COUNT correctly counts the number of rows, BUT it does not display the number = 0, if it is, that is, it displays only what it is. It seems like LEFT JOIN should take that into account.
I need:
pd.d_id | pd.l_id | COUNT(*) 1 | 12 | 1 1 | 11 | 1 1 | 10 | 0 2 | 12 | 2 2 | 11 | 0 2 | 10 | 4 ... Output to me:
pd.d_id | pd.l_id | COUNT(*) 1 | 12 | 1 1 | 11 | 1 2 | 12 | 2 2 | 10 | 4 ... what am i doing wrong?
(people.id, duties.id). Something likeSELECT DISTINCT p.id, d.id FROM people p, dutied d. Then all of them will be present in the output set - incl. and with zeros. - Akina