mysql数据库中,使用SQL统计出每十分钟之内的数据量的大小;


先说表结构:

wKioL1iv727CRBsRAABcw4qsUag323.png-wh_50

想要的结果就是:每十分钟之内的user_id 有多少

方案1:

   select from_unixtime(floor(UNIX_TIMESTAMP(start_time)/600)*600)  ,COUNT(DISTINCT user_id) AS 'count' from  user_live_hits_log_history 

   group by  FLOOR(UNIX_TIMESTAMP(start_time)/600)


方案2:SELECT RPAD(LEFT(start_time,15),19,'0:00') AS start_time , COUNT(DISTINCT user_id) AS 'count' FROM user_live_hits_log_history GROUP BY LEFT(start_time,15)


只要熟悉这几个函数的应用,就会发现很简单的