I have a table similar to this example.
| id | s_id | date |
|---|---|---|
| X | 8 | 2022-03-23 |
| X | 9 | 2022-03-24 |
| X | 9 | 2022-03-24 |
| X | 10 | 2022-03-24 |
I need to get which s_id has been recorded how many times per day. First I thought of grouping and looping the dates and querying the s_id for that date. However, I know that this will cause a loss of performance on too many recordings.
How can I do it using INNER JOIN, JOIN?
If there is no record for that s_id on that date, 0 should be assigned.
I'm planning to get a result like
| date | s_id | total |
|---|---|---|
| 2022-03-23 | 8 | 1 |
| 2022-03-23 | 9 | 0 |
| 2022-03-23 | 10 | 0 |
| 2022-03-24 | 8 | 0 |
| 2022-03-24 | 9 | 2 |
| 2022-03-24 | 10 | 1 |