在MonetDB中工作时,我有一个包含时间值的“入口时间”列。我有:
select "minute"(entrytime) as unitTime, period
from schema1.zones
where date1 >= eDate and date1 <= xDate and id=256
group by unitTime, period
但是我想在15分钟的边界上对结果进行分组,然后返回15分钟块的最大'周期'值,任何想法?
感谢。
答案 0 :(得分:0)
这是R解决方案的示例。我认为您只需要将您的入场时间列转换为您想要的间隔时间?然后你可以用MAX()?
运行一个组# run this line once
# install.packages( "MonetDBLite" )
library(DBI)
x <- data.frame( entrytime = sample( 1:1000 , 10000 , replace = TRUE ) , period = sample( 1:10 , 10000 , replace = TRUE ) )
head( x )
x$intervals <- findInterval( x$entrytime , seq( 0 , 1000 , by = 15 ) )
db <- dbConnect( MonetDBLite::MonetDBLite() )
dbWriteTable( db , 'x' , x )
# max period for distinct minutes
head( dbGetQuery( db , "SELECT entrytime , MAX( period ) FROM x GROUP BY entrytime" ) )
# max period for 15 minute intervals
head( dbGetQuery( db , "SELECT intervals , MAX( period ) FROM x GROUP BY intervals" ) )