Example output
Sure, I can help with that!
Here's the SQL query to retrieve the third highest salary from the "employees" table:
sql
SELECT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 2;
This query first sorts the salaries in descending order using the ORDER BY clause. Then it uses the LIMIT and OFFSET clauses to skip the first two rows (i.e., the two highest salaries) and return the third highest salary.
Note that if there are duplicate salaries, this query will return the third highest distinct salary. If you want to include ties, you can use the DENSE_RANK function instead. Here's an example query that uses DENSE_RANK:
sql
SELECT DISTINCT salary
FROM employees
WHERE DENSE_RANK() OVER (ORDER BY salary DESC) = 3;
This query uses the DENSE_RANK window function to assign a rank to each salary, based on the descending order of salaries. It then filters the result set to include only the rows where the salary has a rank of 3 (i.e., the third highest salary, or the third highest salary in case of ties). The DISTINCT keyword is used to remove duplicates from the result set.