Search
 
SCRIPT & CODE EXAMPLE
 

SQL

nth highest salary in sql

Here is the solution for nth highest
salary from employees table 

SELECT FIRST_NAME , SALARY FROM 
(SELECT FIRST_NAME, SALARY, DENSE_RANK() OVER
(ORDER BY SALARY DESC) AS SALARY_RANK
FROM EMPLOYEES)
WHERE SALARY_RANK = n; 
Comment

nth highest salary in sql

select * from(
select ename, sal, dense_rank() 
over(order by sal desc)r from Employee) 
where r=&n;

To find to the 2nd highest sal set n = 2
To find 3rd highest sal set n = 3 and so on.
Comment

nth highest salary in sql

-- creating Employee table in Oracle
CREATE TABLE Employee (name varchar(10), salary int);

-- inserting sample data into Employee table
INSERT INTO Employee VALUES ('Rick', 3000);
INSERT INTO Employee VALUES ('John', 4000);
INSERT INTO Employee VALUES ('Shane', 3000);
INSERT INTO Employee VALUES ('Peter', 5000);
INSERT INTO Employee VALUES ('Jackob', 7000);

/*
SELECT TOP 1 salary 
FROM (
  SELECT DISTINCT TOP N salary FROM Employee ORDER BY salary DESC 
  ) AS temp 
ORDER BY salary
*/

SELECT TOP 1 salary 
FROM (
  SELECT DISTINCT TOP 1 salary FROM Employee ORDER BY salary DESC 
  ) AS temp 
ORDER BY salary


SELECT TOP 1 salary 
FROM (
  SELECT DISTINCT TOP 2 salary FROM Employee ORDER BY salary DESC 
  ) AS temp 
ORDER BY salary

SELECT TOP 1 salary 
FROM (
  SELECT DISTINCT TOP 3 salary FROM Employee ORDER BY salary DESC 
  ) AS temp 
ORDER BY salary
Comment

PREVIOUS NEXT
Code Example
Sql :: oracle error compilation line 
Sql :: sqlite copy table to another table 
Sql :: database get 10 user aleatory 
Sql :: mysql in 
Sql :: sql join 
Sql :: mysql sql select one day before 
Sql :: mysql composite primary key 
Sql :: sql datum formatieren 
Sql :: find a column by name in a sql server table 
Sql :: change from not null postgresql 
Sql :: execut sql python 
Sql :: insert in sql 
Sql :: how to start my sql server on mac 
Sql :: top 3 salary in sql 
Sql :: sql remove duplicate 
Sql :: sqrt(i) 
Sql :: dublicate row sql 
Sql :: how to relationship query two different tables in MySQL 
Sql :: how to execute MySQL Stored Procedure in Python 
Sql :: mysql delete older duplicates 
Sql :: sql server python connection 
Sql :: postgresql variable in query 
Sql :: drop database mysql 
Sql :: first max salary in sql 
Sql :: mysql sublime build system 
Sql :: sql not equal to operator 
Sql :: querry mysql by 2 columns 
Sql :: psql attribute cannot login 
Sql :: List all the items that have not been part of any purchase order. sql 
Sql :: creating tables in sql with python 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =