MySQL: group by consecutive days and count groups

前端 未结 5 1740
广开言路
广开言路 2020-12-17 20:43

I have a database table which holds each user\'s checkins in cities. I need to know how many days a user has been in a city, and then, how many visits a user has made to a c

5条回答
  •  醉酒成梦
    2020-12-17 21:28

    for a first sub-task:

    select count(*) 
    from (
    select TO_DAYS(p.d)
    from p
    group by TO_DAYS(p.d)
    ) t
    

提交回复
热议问题