📜  SQL SELECT LAST

📅  最后修改于: 2020-11-11 04:33:21             🧑  作者: Mango

SQL选择最后

last()函数用于返回指定列的最后一个值。

SQL SELECT LAST()函数的语法:

SELECT LAST (column_name) FROM table_name;

您应该注意,last()函数仅在MS Access中受支持。但是有一些方法可以获取MySql,SQL Server,Oracle等数据库中的最后一条记录。

SELECT column_name FROM table_name
ORDER BY column_name DESC
LIMIT 1;
SELECT TOP 1 column_name FROM table_name
ORDER BY column_name DESC;
SELECT column_name FROM table_name 
ORDER BY column_name DESC
WHERE ROWNUM <=1;

让我们以客户为例,检查SQL SELECT LAST命令:

表客户

CUSTOMER_NAME AGE ADDRESS EXPENDITURE
KAMAL SHARMA 26 GHAZIABAD 6000
ROBERT PETT 23 NEWYORK 26000
SHIKHA SRIVASTAV 22 DELHI 9000

如果要从“客户”表中检索“客户名称”列的最后一个值,则需要编写以下查询:

SELECT LAST (CUSTOMER_NAME) AS LAST_CUSTOMER FROM CUSTOMERS;
After that query, you will find the result:
SHIKHA SRIVASTAV