Search
 
SCRIPT & CODE EXAMPLE
 

SQL

n highest salary in sql

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

write sql query to find the second highest salary of employee

SELECT MAX(Salary) From Employee
 WHERE Salary < ( SELECT Max(Salary) FROM Employee);
Comment

How to find third 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 3 salary FROM Employee ORDER BY salary DESC 
  ) AS temp 
ORDER BY salary
Comment

sql find second highest salary employee

/* sql 2nd highest salary employee */
select sal, ename
from emp
where sal =
    (
        select max(sal) from emp where sal <
            (select max(sal) from emp)
    )
----------------------------------------------- option 2
select *
from 
(
    select ename, sal, dense_rank() over(order by sal desc) rank
    from emp
)
where rank =2;
Comment

2nd max salary query in sql

select *from employee 
group by salary 
order by  salary desc limit 1,1;
Comment

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 :: clear table sql 
Sql :: sql sequence 
Sql :: oracle simple quote 
Sql :: how to run sql server on mac 
Sql :: mysql add columns 
Sql :: sql column name 
Sql :: declare value in sql 
Sql :: query to find second highest salary 
Sql :: insert into without column names 
Sql :: mysql with 
Sql :: sqlite insert if not exists 
Sql :: sqlalchemy get schema from database 
Sql :: having count oracle two columns 
Sql :: uninstall mysql ubuntu 18.04 stackoverflow 
Sql :: mysql on duplicate key ignore 
Sql :: mysql timestamp vs datetime 
Sql :: mysql create table index 
Sql :: how to define a save method in ruby for sqlite3 databases 
Sql :: oracle show errors compilation 
Sql :: mysql sql select one day before 
Sql :: call function in query sql server 
Sql :: sql order by number not ordered 
Sql :: oracle lock user 
Sql :: datagrip execute procedure 
Sql :: best sql collation 
Sql :: power query datetime to date 
Sql :: mysqldump 1 table only 
Sql :: json to dynamic columns in sql 
Sql :: how to find table lock and row lock in mysql 
Sql :: sqlalchemy case insensitive like 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =