Skip to content
Advertisement

Query with group by date

I’m working on the following user table, where role = 2 means the user is an instructor, and role = 3 means that the user is a student.

My goal is to select the sum value of all instructors and students, grouped by date. The result should look like this:

In this case, on 2020-07-01, I had 1 instructor and 2 students registered and on 2020-08-01, I had no instructors and I had 1 student registered.

My problem is that I am having difficulties in setting up this query, if someone can help me thank you very much!

Advertisement

Answer

You would need count with a case statement as follows

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement