1.SELECT MAX(column_name) AS second_greatest
FROM table_name
WHERE column_name < (SELECT MAX(column_name) FROM table_name);
Replace column_name
with the column you want to find the second greatest value for, and table_name
with your table’s name.
- Using Window Function:
SELECT DISTINCT column_name
FROM (
SELECT column_name, ROW_NUMBER() OVER (ORDER BY column_name DESC) AS row_num
FROM table_name
) AS sub
WHERE row_num = 2;