sql >> Base de Datos >  >> RDS >> Mysql

encontrar el N-ésimo elemento más grande en SQL

Podrías hacer esto:

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