MySQL last函数
MySQL的last函数用于返回所选列的最后一个值。
语法:
SELECT column_name
FROM table_name
ORDER BY column_name DESC
LIMIT 1;
MySQL last function example
考虑一张名为”officers”的表,该表包含以下数据。
执行以下查询:
SELECT officer_name
FROM officers
ORDER BY officer_id DESC
LIMIT 1;
此查询将按officer_id返回最后一个officer_name。
输出:
返回按officer_name排序的最后一个officer_name:
SELECT officer_name
FROM officers
ORDER BY officer_name DESC
LIMIT 1;
输出: