Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Finden Sie das N-größte Element in SQL

Sie könnten dies tun:

SELECT t1.*
FROM (
  SELECT *
  FROM my_table
  ORDER BY value DESC
  LIMIT 1
  OFFSET N -- Set your value for N here, N being 0-based
) t1
RIGHT OUTER JOIN (
  SELECT null -- This will guarantee that you have at least one row
) t2
ON TRUE