I am trying to calculate the how many users are female and how many male, after doing DISTINCT on the UserID
SELECT
COUNT(IF("Gender" = 'female', 1, NULL)) as Ufemale,
COUNT(IF("Gender" = 'male', 1, NULL)) as Umale
FROM (SELECT DISTINCT UserID FROM user_stats where Year='2019' and Account='P') as UID
If I execute the
SELECT DISTINCT UserID FROM user_stats where Year='2019' and Account='P'
It returns the unique UserID. However, if I combine it with count gender part, it returns Zero.
Here is how the values looks like
UserID | Gender
-----------------------------
2018359084885123 | male
1925823664195671 | female
2033134076795519 |
2122445674469149 | female
2315129265210413 | female
2018359084885123 | male
2122445674469149 | female
And the aim is to show
Ufemale | Umale
-------------------
3 | 1
Try this:
Tables
Query
Result
Example: https://rextester.com/JLQ19855