如何使用MySQL命令显示数据库中的最后一分钟(即当前分钟)行?

时间:2016-10-19 04:39:11

标签: mysql

mysql> SELECT * FROM master_name;

+---------+---------------------+---------------------+-----------+----------+
| name_id | name_dateadded      | name_datemodified   | firstname | lastname |
+---------+---------------------+---------------------+-----------+----------+
|       1 | 2001-10-29 13:11:00 | 2001-10-29 13:11:00 | John      | Smith    |
|       2 | 2001-10-29 13:11:00 | 2001-10-29 13:11:00 | Jane      | Smith    |
|       3 | 2001-10-29 13:11:00 | 2001-10-29 13:11:00 | Jimbo     | Jones    |
|       4 | 2001-10-29 13:11:00 | 2001-10-29 13:11:00 | Andy      | Smith    |
|       7 | 2001-10-29 14:16:21 | 2001-10-29 14:16:21 | Chris     | Jones    |

预期产出:

| 7 | 2001-10-29 14:16:21 | 2001-10-29 14:16:21 | Chris  | Jones |

3 个答案:

答案 0 :(得分:0)

你可以尝试这样的事情。

SELECT MAX(name_id) FROM master_name 

答案 1 :(得分:0)

SELECT t.*
FROM master_name
WHERE id = (SELECT MAX(name_id) FROM master_name)

答案 2 :(得分:0)

您甚至可以使用LIMIT

<强>查询

SELECT * FROM `master_name`
ORDER BY `name_id` DESC LIMIT 1;