简体   繁体   中英

SQL phpmyadmin query return most recently date

i have a table in my phpmyadmin database with this colomn and data:

id    sensor    temp    hum    date

--------------------------------------

1     sensor1   15      20     20/12/2016
2     sensor1   18      0      2/10/2015
3     sensor2   22      10     20/12/2016
4     sensor2   30      22     2/10/2015
5     sensor3   25      15     20/12/2016

I want a query that return data like:

id    sensor    temp    hum    date

--------------------------------------

1     sensor1   15      20     20/12/2016
3     sensor2   22      10     20/12/2016
5     sensor3   25      15     20/12/2016

So i want for each sensor, the most recent date and information. How can i do this with a query? Thanks all for help.

EDIT

My date are store in this format:

Thu Sep 29 2016 11:42:59 GMT+0200 (CEST)

EDIT2

I have notated that on my db is activated the only_full_group_by

Try

select `id`,`sensor`,`temp`,`hum`, max(`date`)
from table
GROUP BY  `sensor`;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM