0% found this document useful (0 votes)
6 views

sample question

Uploaded by

b.nagnath194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

sample question

Uploaded by

b.nagnath194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

create database sample;

use sample
create table cust(cust_ID varchar(5),name char(10),sal varchar(10),email_ID
varchar(20))
insert into cust values(1,'pallavi',10000,'[email protected]')
insert into cust values(2,'prakash',20000,'[email protected]')
insert into cust values(3,'pravin',30000,'[email protected]')
insert into cust values(4,'prashant',40000,'[email protected]')
insert into cust values(5,'prem',50000,'[email protected]')
select * from cust

---write a query to find TOP 3 salary and customer details


select top(3)sal,* from cust ---(only top 3 not max or min)

---write a query to find second highest salary and all details


select max(sal) as second_max_sal from cust
where sal<(select max(sal) from cust);

select max(sal) as second_max_sal from cust


where sal not in (select max(sal) from cust);

---write a query to find second highest salary and all details


---inline view

select * from cust c1


where 2 = (select COUNT(distinct sal)
from cust c2
where c1.sal <= c2.sal)

---write a query to find Third highest salary and all details


select * from cust c1
where 3 = (select COUNT(distinct sal)
from cust c2
where c1.sal <= c2.sal)

You might also like