在对UserID进行DISTINCT后,我正在尝试计算有多少用户是女性以及有多少男性
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
如果我执行
SELECT DISTINCT UserID FROM user_stats where Year='2019' and Account='P'
它返回唯一的UserID。但是,如果我将它与count性别部分组合,则返回Zero。
这是值的样子
UserID | Gender
-----------------------------
2018359084885123 | male
1925823664195671 | female
2033134076795519 |
2122445674469149 | female
2315129265210413 | female
2018359084885123 | male
2122445674469149 | female
目的是要表现出来
Ufemale | Umale
-------------------
3 | 1