select orderTimes,count(personID) as num from (select personID,count(orderSN) as orderTimes from `order` where cityID = 某地区id and creatTime >= '2014-12-18' and createTime < '2014-12-19' group by personID) a group by orderTimes order by orderTimes 思路:先按照会员统计消费次数,再按照次数统计会员人数。
select orderTimes,count(personID) as num
from (select personID,count(orderSN) as orderTimes
from `order`
where cityID = 某地区id
and creatTime >= '2014-12-18'
and createTime < '2014-12-19'
group by personID) a
group by orderTimes
order by orderTimes
思路:先按照会员统计消费次数,再按照次数统计会员人数。