如何在MySQL的同一列上计算和检索null和not null?
mytable
---------------------------------------------------
id | name | visited | registDate |
---------------------------------------------------
1 | george | NULL | 2014-04-01 |
---------------------------------------------------
2 | Thomas | NULL | 2014-04-15 |
---------------------------------------------------
3 | Wilfred | 1 | 2014-04-24 |
---------------------------------------------------
4 | paul | 1 | 2014-04-10 |
---------------------------------------------------
5 | elina | NULL | 2014-05-03 |
---------------------------------------------------
6 | angela | NULL | 2014-04-13 |
---------------------------------------------------
7 | elina | 1 | 2014-05-18 |
---------------------------------------------------
预期结果
month register visited not visited
---------------------------------------------
05-2014 2 1 1
---------------------------------------------
04-2014 5 2 3
---------------------------------------------
count(visited)
。count(<column>)将仅计数不为null。如果添加另一层嵌套,则可以将count_not_visited确定为count_registered - count_visited