查询时间内用户分布的sql语句

查询用户某天做某种操作类型时总人数,在一个小时后还剩多少用户,两个小时后还剩多少用户,以此类推,展现出一个分布情况,表名record

img

这个不是很简单吗?

//小时的
select (select count(doc_record_type) from record where doc_record_type = 1 ) as read
from record where doc_record_ctime > ? and doc_record_ctime< ?
//总的
select (select count(doc_record_type) from record where doc_record_type = 1 ) as read
from record


select sum(1) from 表名 group by day(doc_record_ctime),doc_record_type; //获取每天操作类型人数
select sum(1) from 表名 group by day(doc_record_ctime),hour(doc_record_ctime),doc_record_type; //获取每日每小时操作类型人数

代码仅供参考