Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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

query to find third highest salary

-*FOR THIRD HIGHEST SALARY*

Select top 1 from (select top 3 salary from emp order by salary desc)
order by asc
Comment

sql highest salary by location

/*  Highest salary by Department/Location   */
SELECT e.ename, e.sal, e.deptno, d.loc
FROM emp e
JOIN dept d
ON e.deptno = d.deptno
WHERE e.sal in
( 	
  	select max(sal) 
  	from emp 
  	group by deptno
)
Comment

how to get second highest salary in each department in sql

SELECT E.Employers_name, E.dep_number, E.salary
FROM Employers E
WHERE 1 = (SELECT COUNT(DISTINCT salary) 
        FROM Employers B 
        WHERE B.salary > E.salary AND E.dep_number = B.dep_number)
group by E.dep_number
Comment

PREVIOUS NEXT
Code Example
Sql :: SQL ORDER BY DESC (Descending Order) 
Sql :: change filed order in mysql 
Sql :: oracle temporary table 
Sql :: sql running total 
Sql :: sql command to show all tables 
Sql :: mysql decimal allow negative values? 
Sql :: oracle drop sequence 
Sql :: Parsing XML IN SQL Server 
Sql :: update con select postgresql 
Sql :: postgresql not case sensitive where in 
Sql :: postgres duplicate key value violates unique constraint already exists 
Sql :: mysql stored procedure vs function 
Sql :: mysql get nth highest 
Sql :: oracle free up space in tablespace 
Sql :: sql server previous month 
Sql :: how to drop database name in postgresql 
Sql :: mysql date equals to current_date plus days 
Sql :: sql parent child tree query 
Sql :: mysql 8 geo to json 
Sql :: lack create session privilege oracle 
Sql :: sqlserver add column 
Sql :: oracle insert into where 
Sql :: Add image in MySQL database 
Sql :: SQL COUNT() With HAVING Clause 
Sql :: postgres trigger insert into another table 
Sql :: sql query to select data between two dates 
Sql :: oracle session statistics 
Sql :: sql column name 
Sql :: delete from IN subquery 
Sql :: sqlalchemy get schema from database 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =