I have a table of users with three columns.
Username Accepted Rejected
User 1 1 NULL
User 1 1 NULL
User 1 NULL 1
User 2 1 1
User 3 1 NULL
User 3 1 NULL
User 2 NULL 1
User 3 NULL NULL
User 2 NULL NULL
I’d like to show a list of all the users with counts of Accepted/Rejected columns like so:
Username Accepted Rejected
User 1 2 1
User 2 1 2
User 3 2 NULL
What is the best way to do it?
If Accepted and Rejected can contain 1, 0 and null only use sum because sum will return null if all values supplied are null:
Count will return zero in Rejected column of user3.