Northwind数据库,选取价格第二高的产品。
有两种方法,一个是用Row_Number()函数:
SELECT productname FROM (SELECT TOP 2 productname, Row_Number() OVER (ORDER BY unitprice desc) AS rownum FROM Products) AS tbl WHERE rownum = 2;
另一种是对子语句的的结果再进行排序:
SELECT top 1 productname FROM (SELECT TOP 2 productname,unitprice FROM Products order by unitprice desc) AS tbl order by tbl.unitprice asc
SQL学习笔记:选取第N条记录,布布扣,bubuko.com
时间: 2024-10-10 13:49:22