Is this possible with mysql?

前端 未结 6 1927
走了就别回头了
走了就别回头了 2021-01-16 12:42

First of all: sorry for the title, but maybe I will find a better one later.

I asked this some minutes ago, but since I was not able to describe what I want I try it

6条回答
  •  無奈伤痛
    2021-01-16 13:24

    You need to add a subquery that loads the data from the specified range (eg, 1day/2day/7days) and compares it with the data for the current day.

    set @range = 7;
    select * from gc_sessions
    WHERE user in (SELECT user from gc_sessions
    where starttime between subdate(current_date, @range) AND subdate(current_date, 1))
    
    AND starttime > subdate(current_date, 0)
    

    Where @range holds information about the number of days. See your expanded sql fiddle at - http://sqlfiddle.com/#!2/9584b/24

提交回复
热议问题