My Data Base is an SQL server And My Query Is Below
SELECT name, MAX(average) AS average
FROM Course
WHERE salary <> (SELECT MAX(salary)
FROM Course);
I Want Get Second Highest Average in Class
SELECT name, average AS average
FROM Course
WHERE average = (SELECT Top(2) MAX(salary)
FROM Course)
No dbms specified but for MySQL and PostgreSQL You can use the limit and offset to get the second highest grade. Remove the MAX
aggregation on the average
column.
SELECT name, average AS average
FROM Course
WHERE salary <> (SELECT MAX(salary)
FROM Course)
ORDER BY average DESC
LIMIT 1,2;
In MSSQL > 2012 you can use OFFSET and FETCH
OFFSET 1 ROWS
FETCH NEXT 1 ROWS ONLY;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With