SQL Queries+5Tables
SQL Queries+5Tables
2023-24
Submitted By:____________
Class: XIIth
Submitted To:
CERTIFICATE
CLASS: Xii- YEAR:2023-24
PRINCIPAL
Acknowledgement
(i) Display the Mobile company, Mobile name & price in descending order of
their manufacturing date.
Ans. SELECT M_Compnay, M_Name, M_Price FROM MobileMaster
ORDER BY M_Mf_Date DESC;
(ii) List the details of mobile whose name starts with “S”.
Ans. SELECT * FROM MobileMaster
WHERE M_Name LIKE “S%‟;
(iii) Display the Mobile supplier & quantity of all mobiles except “MB003‟.
Ans.SELECT M_Supplier, M_Qty FROM MobileStock
WHERE M_Id <>”MB003”;
(iv) To display the name of mobile company having price between 3000 & 5000.
Ans. SELECT M_Company FROM MobileMaster
WHERE M_Price BETWEEN 3000 AND 5000;
**Find Output of following queries
(v) SELECT M_Id, SUM(M_Qty) FROM MobileStock GROUP BY M_Id;
MB004 450
MB003 400
MB003 300
MB003 200
(vi) SELECT MAX(M_Mf_Date), MIN(M_Mf_Date) FROM MobileMaster;
2017-11-20 2010-08-21
(vii) SELECT M1.M_Id, M1.M_Name, M2.M_Qty, M2.M_Supplier
FROM MobileMaster M1, MobileStock M2 WHERE M1.M_Id=M2.M_Id
AND M2.M_Qty>=300;
MB004 Unite3 450 New_Vision
SQL 2
i. Display the Trainer Name, City & Salary in descending order of theirHiredate.
Ans. SELECT TNAME, CITY, SALARY FROM TRAINER
ORDER BY HIREDATE;
ii. To display the TNAME and CITY of Trainer who joined the Institute in
the month of December 2001.
Ans. SELECT TNAME, CITY FROM TRAINER
WHERE HIREDATE BETWEEN ‘2001-12-01’
AND ‘2001-12-31’;
iii. To display TNAME, HIREDATE, CNAME, STARTDATE from
tables TRAINER and COURSE of all those courses whose FEES is less than
or equal to 10000.
Ans. SELECT TNAME,HIREDATE,CNAME,STARTDATE FROM TRAINER, COURSE
WHERE TRAINER.TID=COURSE.TID AND FEES<=10000;
iv. To display number of Trainers from each city.
Ans. SELECT CITY, COUNT(*) FROM TRAINER
GROUP BY CITY;
**Find Output of following queries
v. SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT IN(‘DELHI’,
‘MUMBAI’);
Ans.
103 DEEPTI
106 MANIPRABHA
vi. SELECT DISTINCT TID FROM COURSE;
Ans.
101
103
102
104
105
vii. SELECT TID, COUNT(*), MIN(FEES) FROM COURSE GROUP BY TID
HAVING COUNT(*)>1;
Ans. 101 2 12000
viii. SELECT COUNT(*), SUM(FEES) FROM COURSE WHERE STARTDATE<
‘2018-09-15’;
Ans. 4 65000
SQL 3
SQL 4
i. To display all the details of those watches whose name ends with ‘Time’
Ans select * from watches
where watch_name like ‘%Time’;
ii. To display watch’s name and price of those watches which have price range in
between 5000-15000.
Ans. select watch_name, price from watches
where price between 5000 and 15000;
iii. To display total quantity in store of Unisex type watches.
Ans. select sum(qty_store) from watches where type like
’Unisex’;
iv. To display watch name and their quantity sold in first quarter.
Ans. select watch_name,qty_sold from watches w,sale s
where w.watchid=s.watchid and quarter=1;
v. select max(price), min(qty_store) from watches;
Ans. 25000 100
vi. select quarter, sum(qty_sold) from sale group by quarter;
1 15
2 30
3 45
4 15
vii. select watch_name,price,type from watches w, sales where
w.watchid!=s.watchid;
HighFashion 7000 Unisex
viii. select watch_name, qty_store, sum(qty_sold), qty_store -sum(qty_sold)
“Stock” from watches w, sale s where w.watchid=s.watchid group by s.watchid;
HighTime 100 25 75
LifeTime 150 40 110
Wave 200 30 170
Golden Time 100 10 90
SQL 5
(i) To display the records from table student in alphabetical order as per the name
of the student.
Ans. Select * from student
order by name;
(ii ) To display Class, Dob and City whose marks is between 450 and 551.
Ans. Select class, dob, city from student
where marks between 450 and 551;
(iii) To display Name, Class and total number of students who have secured more
than 450 marks, class wise
Ans. Select name,class, count(*) from student
group by class
having marks> 450;
(iv) To increase marks of all students by 20 whose class is “XII
Ans. Update student
set marks=marks+20
where class=’XII’;
**Find output of the following queries.
(v) SELECT COUNT(*), City FROM STUDENT GROUP BY CITY HAVING
COUNT(*)>1;
2 Mumbai
2 Delhi
2 Moscow
(vi ) SELECT MAX(DOB),MIN(DOB) FROM STUDENT;
08-12-1995 07-05-1993
(iii) SELECT NAME,GENDER FROM STUDENT WHERE CITY=’Delhi’;
Sanal F
Store M