【发布时间】:2017-08-13 14:13:31
【问题描述】:
我正在尝试从恰好存储多个状态的表中获取最后一个日期时间记录。我的桌子是这样的:
+---------+--------------------+-------+-------+
|status_id|status_timestamp |User id|Status |
+---------+--------------------+-------+-------+
|1 |2012-02-14 12:04:45 |2 |active |
|2 |2012-02-14 12:14:20 |2 |inactive| <-want that value only
|3 |2013-02-14 12:20:59 |3 |desact |
+---------+--------------------+-------+-------+
SELECT st.Status, st.status_timestamp
FROM status_table as st
INNER JOIN user_profile as up ON st.user_id = up.user_id
WHERE up.username = "usertest";
usertest 是 user_id 2
我尝试使用 max(st.status_timestamp) 但我无法让它工作
【问题讨论】:
-
这两个问题在我进行研究时都不知道存在,但如果你想删除它,我很好。
标签: mysql