Frequently ask question in Sql interview

Frequently ask question in Sql interview


Find the highest salary in sql



SELECT [Name],
       [Age],
       [Address],
       [Salary],
  FROM [salarydetails]




Name Age     Address         Salary
Jhon    21        UK                10000.00
Sham  21        India             100000.00
Allen  21       US                  90000.00
Shyam 21       America        60000.00
Seema 21       Rashia           50000.00


Find maxium salary

select max(salary) as maxiumsalary from salarydetails

Output:

    maxiumsalary
    100000.00

Note: (here  maximumsalary is virtual column means, i am aliasing the column name now it  will look like maximumslary column in output)

Find the average of  salary using AVG function

select avg(salary) as avgsalary from salarydetails

Output:
Output:

avgsalary
62000.000000

Find the 2nd highest salary

select max(salary) as secondhighest from salarydetails where  salary not in(select MAX(salary) from salarydetails)

Output:

secondhighest
90000.00


Find the 3rd  highest salary


select min (salary) from (select top 3* from salarydetails)m


Thanks for reading my blog

Post a Comment

Post a Comment (0)

Previous Post Next Post