嗨,我想選擇一個表格按日期desc比gruoup由smth。起初phpmyadmin給出了一個錯誤(sql_mode = only_full_group_by),我通過從my.cnf中刪除該標誌來修復它,並且我不知道這個修復是否適合長期使用,我在某處使用此修復可以獲得不需要的結果。我試過**select * from (select * from log order by date desc) tmp group by imei**
,但結果是從最早的日期,而不是從最新的日期,它給了我從第一個ID不是從最後一個imei。Mysql select date by desc then group by column
回答
對於分組結果,如果您訂購了輸入,則無關緊要。如果我正確解釋你的問題,你想獲得每個imei的最新日誌條目。你將不得不做這樣的事情:
SELECT l1.*
FROM logs as l1
LEFT OUTER JOIN logs as l2
ON l1.imei = l2.imei
AND l1.date < l2.date
WHERE l2.date IS NULL
,你基本上是要求每個日誌條目(L1),對於沒有日誌條目(L2)具有相同IMEI存在,但更大的日期。
如果你只是想知道當每個IMEI最後的日誌條目,這將是不夠的:
SELECT imei, MAX(date)
FROM log
GROUP BY imei
我已經建立了d你的第一個命令,但它需要很長的時間,我不會收到一個結果,它只是停留在加載。我想要做的只是你做了第二步命令,但我想選擇所有列不只是imei和日期 –
我已經刪除了哪裏l2.date爲空,但它給了我表中的所有數據不唯一數據由imei –
如果結果需要很長時間,則應在imei和日期列上添加索引。 當您刪除「WHERE l2.date IS NULL」部分時,您會要求輸入所有條目,這就是您會得到的。 – seven77
SELECT * FROM日誌WHERE ID IN(SELECT MAX(ID)從IMEI日誌組)
- 1. group by by desc
- 2. MySQL group by without column name
- 3. mySQL order by certain values&then DESC?
- 4. Mysql的GROUP BY和ORDER BY DESC
- 5. MYSQL SELECT GROUP BY
- 6. MySQL - 使用GROUP BY和DESC
- 7. MySQL select table column 31-12-2014 type varchar as date date by date php
- 8. SQL select by desc
- 9. vb.net group by then by order by Linq
- 10. GROUP BY + MAX(date)
- 11. Group By Then Aggregate
- 12. mysql select all,group by orderid
- 13. group by by by by mysql
- 14. MySQL,要反向SELECT GROUP BY
- 15. SQL Group by MAX(Date)
- 16. MYSQL GROUP BY/ORDER BY confusion
- 17. SELECT COUNT,GROUP BY,ORDER BY
- 18. Mysql group by by by by?
- 19. MySQL count group by
- 20. MySQL ORDER BY,GROUP BY內JOIN
- 21. Mysql Group by time by mutilple condition
- 22. oracle group by date with specific time
- 23. MYSQL SUM GROUP BY
- 24. MySQL的SELECT JOIN和GROUP BY
- 25. SELECT GROUP BY用戶
- 26. Entity Framework Group By Then Order
- 27. Linq group by select
- 28. MySQL查詢與GROUP BY和ORDER BY時間戳DESC
- 29. group by by rollup
- 30. MySQL GROUP by Regex?
'select * from(select * from log order by date desc)tmp group by imei'和'select * from(select * from log order by date)tmp group by imei' –
我現在試過了'select * from(select * from date order by date desc limit 100)tmp group by imei'並且它正在工作,但我不想限制結果 –