数据库表里有多个时间数据,只想取每天5分钟、10分钟、1小时、4小时整点的数据,其他时间点的不要,sql可以这样写:
postgreSql
log_time的类型为timestamp
5min整点:select log_time from XXX where mod(extract(minute from log_time)::int,5) = 0
10min整点:select log_time from XXX where mod(extract(minute from log_time)::int,10) = 0
1小时整点:select log_time from XXX where extract(minute from log_time) = 0
4小时整点:select log_time from XXX where mod(extract(hour from log_time)::int,4) = 0 and extract(minute from log_time) = 0
extrac()截取时间函数
sqlserver
date_time数据类型为datetime
where RIGHT(CONVERT(varchar(19),data_time,120),5)='00:00'
mysql
date_time数据类型为datetime
where RIGHT(data_time,5)='00:00'
oracle
date_time数据类型为TIMESTAMP
where substr(to_char(data_time,'yyyy-mm-dd hh:mi:ss'),15,5)='00:00'
---------------------
参考:https://blog.csdn.net/weixin_37449469/article/details/81535841