I have two tables, “users” & “projects”
users table:
id username
1 sam
2 peter
3 andy
projects table:
id title uid
1 pr1 0
2 pr2 1
3 pr3 2
4 pr4 1
projects.uid represents the user id who will do the job and 0 means this project is not assigned to any user yet.
I want a query to count and group projects based on users & return something like this:
uid project_count
0 1
1 2
2 1
3 0
Thanks so much for your answers but none of them seems to return right rows,
here is my newly found answer:
I’m not pretty sure about it’s performance but currently it works…