在 MySQL 中获取每一天的最后一行

Man*_*noj 3 mysql

我在为 max(datetime) 记录选择其他列时遇到问题。通俗地说,我需要获取相关列,其中 max(DialDateTime) 记录 Mysql 中的所有日期。

 mysql> select max(DialDateTime) as max from log_AP group by   date(DialDateTime) ;
 +---------------------+
 | max                 |
 +---------------------+
 | 2012-12-03 07:37:26 | 
 | 2012-12-04 07:37:04 | 
 | 2012-12-05 07:37:04 | 
 | 2012-12-06 07:37:04 | 
 | 2012-12-07 07:37:04 | 
 | 2012-12-08 07:37:04 | 
 | 2012-12-09 07:37:04 | 
 +---------------------+
Run Code Online (Sandbox Code Playgroud)

7 行(0.00 秒)

Tar*_*ryn 6

您应该能够使用子查询来获取最大日期,然后将其加入您的表以返回剩余的列:

select a1.*
from log_AP a1
inner join
(
  select max(DialDateTime) as max 
  from log_AP 
  group by date(DialDateTime)
) a2
  on a1.DialDateTime = a2.max
Run Code Online (Sandbox Code Playgroud)