Return last value of each day in mysql

Asked

Viewed 31 times

0

Hello, I have following values in the database:

data       -           valor
2019-06-03 7:00        9
2019-06-03 12:00       21
2019-06-03 20:00       28
2019-06-02 8:00        11
2019-06-02 12:30       21
2019-06-02 19:50       27
2019-06-01 8:30        10
2019-06-01 14:00       20
2019-06-01 21:00       29

I need the last value of each day, in case the result would have to be the following:

data       -           valor
2019-06-03 20:00       28
2019-06-02 19:50       27
2019-06-01 21:00       29

How can I have this result in mysql?

1 answer

1


I believe that there are several ways to do this consultation

Here’s an example I did and tested

SELECT data, valor FROM `tabela` where data in (
    SELECT MAX(data) FROM `tabela` GROUP BY date(data)
)

Exit

2019-06-03 20:00:00 28
2019-06-02 19:50:00 27
2019-06-01 21:00:00 29

Browser other questions tagged

You are not signed in. Login or sign up in order to post.