回复最后两位客户的ID和名称

时间:2017-07-02 14:31:49

标签: sql sql-server

我尝试过使用以下查询但不起作用。

select Customer_id,Customer_Name from Customer 
order by Customer_id limit 2

3 个答案:

答案 0 :(得分:1)

试试这个:

SELECT TOP 2 Customer_id, Customer_Name FROM Customer
ORDER BY Customer_id DESC

ORDER BY Customer_id DESC部分获取最后两个ID。

答案 1 :(得分:0)

在SQL Server上,正确的语法是

sorting

对于您的特定情况,它将是

SELECT TOP [number][%]...

答案 2 :(得分:0)

正如Prdp所说,使用top会解决它。

select top 2 Customer_id,Customer_Name from Customer 
order by Customer_id