Thursday, 16 March 2017

Write a sql query to get second highest number?

create table Employee
(
  Id int Identity(1,1),
  Name varchar(100),
  Salary decimal(18,2)
)



insert into Employee(Name,Salary) values('Ashish',5000),('smita',10000),('Rahul',2000)



select 
       t.Name,
       t.Id,
       t.Salary
       from Employee1 t 
       where 3 = (
               select 
               count(distinct t1.salary) 
       from Employee1 t1 
               where t1.Salary >= t.Salary
)

No comments:

Post a Comment