18 SQL Commands
18 SQL Commands
2022
Problem definition:
1. Consider the following tables WORKER and PAYLEVEL and answer the questions that
follows:
TABLE : WORKER
ECODE NAME DESIGN PLEVEL DOJ DOB
11 RadheShyam Supervisor P001 2004-09-12 1981-08-23
12 Chandernath Operator P003 2010-02-22 1987-07-12
13 Fizza Operator P003 2009-06-14 1983-10-14
14 Ameen Ahmed Mechanic P002 2006-08-21 1984-03-13
15 Sanya Clerk P002 2005-12-19 1983-06-09
18 Sarsa Supervisor P001 2010-01-20 1982-02-01
TABLE : PAYLEVEL
PLEVEL PAY ALLOWANCE
P001 26000 12000
P002 22000 10000
P003 12000 6000
Write SQL commands for the following statements:
1. To display the details of all the WORKERS in descending order of their DOJ.
Query:
SELECT * FROM WORKER ORDER BY DOJ DESC;
Output:
2. To display the NAME and DESIG of those WORKERS whose PLEVEL is either P001 or
P002.
Query:
SELECT NAME,DESIGN FROM WORKER WHERE PLEVEL = 'P001' OR PLEVEL = 'P002';
Output:
3. To display the number of workers whose PAY+ALLOWANCE is more than 30000 for every
PLEVEL.
Query:
select plevel,count(*) from paylevel where (pay+allowance)>30000 group by plevel ;
Output:
4. To increase the ALLOWANCE by 1000 where the pay is greater than 20000.
Query:
update paylevel set allowance=allowance+1000 where pay>20000;
Output:
SCODE COUNT(*)
108 1
103 1
101 2
(ii) To display details of those sports and coachname which are having
Prizemoney more than 9000 and coachname ends with ‘n’.
Query:
select sportsname,name from sports s,coach c where s.scode=c.scode and
prizemoney>9000 ;
Output:
SPORTSNAME NAME
Lawn Tennis Mohan
(iii) To display the contents of the sports table with their coachname whose
schedule date is in the year 2012.
Query:
select s.scode,sportsname,participants,prizemoney,scheduledate,name from sports
s,coach c where scheduledate like '%2012' and s.scode=c.scode;
Output:
(v) Increase the Participants by 6 for the sports carom, chess and badminton.
Query:
update sports set participants=participants+6 where sportsname in
('carrom','chess','badminton');
Output:
i) To display those company name which are having prize less than 30000.
Query:
select company.name from company,customer where company.cid=customer.cid
and price<30000;
Output:
iv) To add one more column totalprice with decimal(10,2) to the table customer.
Query:
alter table customer add totalprice decimal(10,2);
Output:
v) Display the product name, city, price where the productname is mobile.
Query:
select productname,city,price from customer, company where productname
='mobile' and customer.cid = company.cid;
Output:.