As mentioned in scaisEdge, you should use group by
:
select
YEAR(member_joindate) AS year, MONTH(member_joindate) AS month, COUNT(DISTINCT member_id) AS joins
from
sdg_members
where
member_joindate BETWEEN '2015-02-30' AND '2016-12-31'
group by
YEAR(member_joindate), MONTH(member_joindate)
This will give you results in the form
year | month | joins
2015 | 3 | 10
2015 | 4 | 3
2015 | 5 | 11
...
After that, you no longer need to apply num_rows
, you just need to go through the result set
source
share