0

我有一个表格,它本质上是每个用户的活动日志,我想显示自用户上次活动以来已经过了多长时间。

询问:

SELECT message_log.log_phone_number, message_log.log_updated
FROM message_log
WHERE message_log.log_mode = “inbound”
GROUP BY  message_log.log_phone_number

结果

415407XXXX  2012-03-07 13:34:14      
434242XXXX  2012-03-07 16:00:42          
434465XXXX  2012-03-07 14:49:15          
434989XXXX  2012-03-07 15:30:22          
757615XXXX  2012-03-07 15:30:54          
804651XXXX  2012-03-07 14:13:04          
920917XXXX  2012-03-07 15:11:28

问题:我的结果显示最旧的时间戳,我想要最新的。有什么办法可以ORDER在里面GROUP BY吗?

4

2 回答 2

3
SELECT message_log.log_phone_number, max(message_log.log_updated) 
FROM message_log 
WHERE message_log.log_mode = “inbound” 
GROUP BY message_log.log_phone_number
于 2012-05-02T12:50:11.917 回答
2

你只需要一个 MAX()。

SELECT message_log.log_phone_number, 
MAX(message_log.log_updated) as log_updated
FROM message_log
WHERE message_log.log_mode = “inbound”
GROUP BY  message_log.log_phone_number
于 2012-05-02T12:50:41.267 回答