L
L
leon84612021-08-11 18:20:54
MySQL
leon8461, 2021-08-11 18:20:54

How to get the last entry for each day if the date is stored as an integer?

How to get the last entry for each day if the date is stored as an integer?
6113eaae2299b676385522.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-08-11
@leon8461

Something like this:

select * from (
  select 
  *,
  date(from_unixtime(created_at)) created_date,
  row_number() over (partition by created_date order by created_at desc) rn
  from tbl) row_numbers where rn = 1

or like this:
select tbl.* from tbl
join (
    select max(created_at) max_created_at
    from tbl
    group by date(from_unixtime(created_at))
) last_time on last_time.max_created_at = tbl.created_at;

Check SQL here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question