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

时间:2017-07-03 17:38:49

标签: sql ms-access

如何在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;

2 个答案:

答案 0 :(得分:2)

您可以使用子查询:

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

答案 1 :(得分:-1)

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 LIMIT 1;