1.这是一个每300秒既是5分钟的间隔的分组 hana 写法,依照原理其他数据库写法雷同
select add_seconds(to_date(recordtime),to_int(SECONDS_BETWEEN(to_date(recordtime),recordtime)/300)*300) rt
from table where recordtime>=to_date('2016-01-10')
group by add_seconds(to_date(recordtime),to_int(SECONDS_BETWEEN(to_date(recordtime),recordtime)/300)*300)
order by rt
写法的原理就是除以间隔秒数,取整后然后再乘以分段的间隔秒数,就是将时间进行离散化处理,譬如0 5 10 15,比如0-4除以5取整后是0,5-9除以5取整后是1