如何在SQL Access数据库表中找到第11个条目?

前端之家收集整理的这篇文章主要介绍了如何在SQL Access数据库表中找到第11个条目?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在Access sql数据库表中找到第11个条目?我必须使用TOP函数,我的查询目前看起来像这样:
SELECT TOP 11 Passenger.Name,SUM(Manifest.Ticketprice) AS [Total Amount Spent on Tickets]
FROM Passenger INNER JOIN Manifest ON Passenger.PassengerNumber=Manifest.PassengerNumber
GROUP BY Passenger.Name
ORDER BY SUM(Manifest.Ticketprice) DESC;

解决方法

您可以使用子查询
SELECT TOP 1 T.Name,T.[Total Amount Spent on Tickets]
FROM

(SELECT TOP 11 Passenger.Name,SUM(Manifest.Ticketprice) AS [Total Amount Spent on Tickets]
FROM Passenger INNER JOIN Manifest ON Passenger.PassengerNumber=Manifest.PassengerNumber
GROUP BY Passenger.Name
ORDER BY SUM(Manifest.Ticketprice) DESC) As T

ORDER BY T.[Total Amount Spent on Tickets] ASC

猜你在找的MsSQL相关文章