首页  编辑  

MySQL 按时间切片分组

Tags: /MySQL/   Date Created:

例如按15分钟,一个组:

SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(NOW())- UNIX_TIMESTAMP(NOW())%(15*60))

对时间严格按照某个时间段切片:

SET @_START = FROM_UNIXTIME(UNIX_TIMESTAMP(NOW())- UNIX_TIMESTAMP(NOW())%(30*60));

SELECT @_START;