這裏有一個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"))