如何根据mysql中的10分钟间隔获得结果 [英] how to get result based on 10 minutes interval in mysql

查看:29
本文介绍了如何根据mysql中的10分钟间隔获得结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 10 分钟的间隔内找到十个搜索最多的不同目的地?

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

预期输出/类似输出

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

我试过下面的代码,

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;

推荐答案

我通过以下查询找到了解决方案.

i have found the solution by below query.

select a.time_column,group_concat(a.destination order by ct desc) from  (select case 
            when time between '00:00:00' and '00:10:00' then '00:10:00'
            when time between '00:10:01' and '00:20:00' then '00:20:00'
            when time between '00:20:01' and '00:30:00' then '00:30:00'
        else '00:00:00' end as time_column 
        , destination
        , count(destination) ct
from click
group by time_column,destination
order by time_column,count(destination) desc limit 10)a
group by a.time_column;

这篇关于如何根据mysql中的10分钟间隔获得结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆