我正在嘗試返回記錄編號(hào)的歷史位置我所擁有的是:SELECT l.location, t.transaction_id, t.date_modified FROM transactions as tINNER JOIN (SELECTt1.received_id, t1.transaction_id, t1.date_modifiedFROM ( SELECT received_id, MAX(date_modified) as maxmodify FROM transactions GROUP BY received_id) as max_recordJOIN transactions as t1 ON (t1.received_id =max_record.received_id)) as whateverINNER JOIN locations as lON l.location_id = t.location_idINNER JOIN received as rON r.received_id = t.received_idWHERE t.received_id='1782'ORDER BY t.date_modified DESC解析大約需要1分鐘,并返回如下數(shù)據(jù):T-E1A 67294 2013-05-29 14:05:30T-E1A 67293 2013-05-29 14:05:30T-E1A 67294 2013-05-29 14:05:30T-E1A 67293 2013-05-29 14:05:30T-E1A 67294 2013-05-29 14:05:30T-E1A 67293 2013-05-29 14:05:30T-E1A 67294 2013-05-29 14:05:30我真正希望看到的是像這樣的查詢中的數(shù)據(jù):SELECT l.location, t.transaction_id, t.date_modified FROM transactions as tJOIN locations as lON l.location_id = t.location_idJOIN received as rON r.received_id = t.received_idWHERE t.received_id='1782'ORDER BY t.date_modified DESC哪個(gè)返回T-E1A 67290 2013-05-29 13:58:26T-E1A 67289 2013-05-29 13:58:26ADJUST 67283 2013-04-26 11:33:54ADJUST 67284 2013-04-26 11:33:54ST10 67279 2013-04-26 09:52:41ST10 67278 2013-04-26 09:52:13ST10 67277 2013-04-26 09:50:58ST10 67276 2013-04-26 09:50:20SH3 67274 2013-04-26 09:49:39第二個(gè)查詢更好,但我真的只想顯示每個(gè)記錄ID和位置的最后修改時(shí)間。有人可以看到我在做什么嗎?感謝您的幫助。
MYSQL在聯(lián)接語(yǔ)句中選擇MAX日期
繁華開(kāi)滿天機(jī)
2019-10-04 14:38:36