Query in mysql to select the current record depending on the date

1

They could help me with a consultation

I have this query

select jornada, min(date_game_large) as date_start, max(date_game_large) as date_end from mi_tabla 
group by jornada order by jornada

where you return this to me:

journay     date_start      date_end
1           1501023600      1501115400
2           1501628400      1501722000
3           1502233200      1502326800
4           1502838000      1502929800
5           1504047600      1504227600
6           1505257200      1505350800
16          1508886000      1508972400

that is when the day begins and when it ends and from there I would like to obtain the day in which we find ourselves by the date that is in timestamp format.

try it like this:

select jornada, min(date_game_large) as date_start, max(date_game_large) as date_end from mi_tabla group by jornada order by jornada
where (date_start BETWEEN UNIX_TIMESTAMP(NOW()) AND date_end)   

but that error marks me:

#1054 - Unknown column 'date_start' in 'where clause'

Could you please help me?

Thanks Greetings

    
asked by skycomputer2 09.10.2017 в 21:11
source

1 answer

2

The error is that you are trying to filter by an alias and not by the name of the column itself, instead of using date_start in the where you should use min (date_game_large).

    select jornada, min(date_game_large) as date_start, max(date_game_large) as date_end from mi_tabla group by jornada order by jornada
where (min(date_game_large) BETWEEN UNIX_TIMESTAMP(NOW()) AND date_end) 
    
answered by 09.10.2017 в 21:22