Mysql
 sql >> Database >  >> RDS >> Mysql

trova l'N-esimo elemento più grande in SQL

Potresti farlo:

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