Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

sql - how to get result based on 10 minutes interval in mysql

How to find ten most search distinct destinations for 10 minutes interval?

    user_id             time        action  destination place
    2017032000000000097 00:00:00    Click   Rimini  Regina Elena 57
    2017032000000000097 00:03:53    Click   Sant    Regina Elena 571
    2017032000000000097 00:01:16    Click   Regina  Regina Elena 572
    2017032000000000097 00:04:34    Click   Rimini  Regina Elena 57
    2017032000000000129 00:07:32    Click   Berlin  M??ggelsee Berlin
    2017032000000000129 00:18:36    Click   GRC     SensCity Berlin Spandau
    2017032000000000129 00:16:12    Click   Berlin  Azimut Berlin City South

expected output/similar output

time            destination(top 10 during 10 minute interval) 
-------------   ---- 
00:00:00        NULL
00:10:00        Rimini,Sant,Regina
00:20:00        Berlin,Grc
00:30:00        NULL

i have tried below code,

select destination , count(user_id),time from click
where MINUTE(time)>= MINUTE(now())-10 and MINUTE(time)< minute(now()) and destination is not null
group by destination,MINUTE(time)>= MINUTE(now())-10 and MINUTE(time)< minute(now()) order by count(user_id) desc;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
select destination , count(id) from your_table
where MINUTE(time)>= MINUTE(now())-10 and MINUTE(time)< minute(now()) 
group by destination 
LIMIT 10

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...