CREATE TABLE air
(id INT AUTO_INCREMENT, latlng varchar(50), pm int, datestamp datetime, PRIMARY KEY (id) )
;
INSERT INTO air
(latlng, pm, datestamp)
values
('20,30', 10 , '2016-05-22 00:00:00') ,
('20,30', 50 , '2016-05-22 10:10:00') ,
('20,30', 40 , '2016-05-22 10:30:00') ;
-- 原查詢語法: 舊紀錄在前
-- SELECT * FROM `air`;
-- 查詢語法2: 新紀錄在前
SELECT tmp.* FROM
( SELECT * FROM `air` ORDER BY `datestamp`
) tmp GROUP BY `latlng` ;
Q1JFQVRFIFRBQkxFIGFpcgooaWQgSU5UIEFVVE9fSU5DUkVNRU5ULCBsYXRsbmcgdmFyY2hhcig1MCksIHBtIGludCwgZGF0ZXN0YW1wIGRhdGV0aW1lLCBQUklNQVJZIEtFWSAoaWQpICkKOwpJTlNFUlQgSU5UTyBhaXIKKGxhdGxuZywgcG0sIGRhdGVzdGFtcCkKdmFsdWVzCignMjAsMzAnLAkxMAksCScyMDE2LTA1LTIyIDAwOjAwOjAwJykJLAooJzIwLDMwJywJNTAJLAknMjAxNi0wNS0yMiAxMDoxMDowMCcpCSwKKCcyMCwzMCcsCTQwCSwJJzIwMTYtMDUtMjIgMTA6MzA6MDAnKQk7Ci0tIOWOn+afpeipouiqnuazlTog6IiK57SA6YyE5Zyo5YmNCi0tIFNFTEVDVCAqIEZST00gYGFpcmA7CgotLSDmn6XoqaLoqp7ms5UyOiDmlrDntIDpjITlnKjliY0KU0VMRUNUIHRtcC4qIEZST00gCiggU0VMRUNUICogRlJPTSBgYWlyYCBPUkRFUiBCWSBgZGF0ZXN0YW1wYAopIHRtcCBHUk9VUCBCWSBgbGF0bG5nYCA7