SQL Programs
SQL Programs
Q.No 1) Consider the following table PRODUCT. Write SQL commands for the statements
(i) to (v)
Table: PRODUCT
P_ID ProductName Manufacturer Price
TP01 TalcomPowder LAK 40
FW05 Face Wash ABC 45
BS01 Bath Soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face Wash XYZ 95
(ii) To display the details of Products whose Price is in the range of 50 to 100(Both values
included).
(v) To display the Maximum Price of the Product whose Manufacturer is XYZ.
(i) Arrange the contents of the table FLIGHTS in the ascending order of FL_NO.
(iv) Display the details of flights in which FL_NO starts with ‘IC’.
(ii) To display NAME and DESIG of those WORKERs, whose PLEVEL is either P001 or
P002.
Ans: select NAME, DESIG from WORKER where PLEVEL = ‘P001’ or PLEVEL=’P002’ ;
(iii) To display the content of all the WORKERs, whose DOB is in between '19-JAN-
1984' and '18-JAN-1987'.
Ans: select * from WORKER where DOB between ’19-01-1984’ and ’18-01-1987’ ;
(iv) To display the NAME, DOJ of those WORKERs whose DOJ is after ’14-Jun-2009’ .
Ans: select NAME, DOJ from WORKER where DOJ > ’14-06-2009’ ;
(iii) To display the content of the RESULT table in alphabetic order of SubjectName
whose exam date is on or after 20-Mar-2015.
(iv) Display all information about the ‘Computer Sc’ from the above table.
Ans: select Scode, SubjectName from RESULT where SubjectName like ‘C%’ ;
Q.No 5) Consider the following table FACULTY. Write SQL commands for the statements
(i) to (v)
(i) To display details of those Faculties whose date of joining is before 31-12-2001.
(ii) To display F_ID, Fname, Lname of those faculties whose Salary is more than 10000.
Ans: select F_ID, Fname, Lname from FACULTY where Salary > 10000 ;
(iii) To display Fname, Lname of those faculties whose Lname starts with ‘M’ ;
Ans: Select Fname, Lname from FACULTY Where Lname like ‘M%’;
(v) To display details of those Faculties in the descending order of their Lname.
]
Q.No 6) Consider the following table GRADUATE. Write SQL commands for the statements
(i) to (v)
TABLE : GRADUATE
SNO NAME STIPEND SUBJECT AVERAGE DIV
1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMP SC 68 I
3 REKHA 350 PHYSICS 56 II
4 ARJUN 500 MATHS 70 I
5 SABINA 400 CHEMISTRY 55 II
6 RUBINA 500 COMP SC 62 I
i) List the names of those students who have obtained DIV I sorted by NAME.
Ans: select NAME from GRADUATE where DIV = ‘I’ order by NAME ;
ii) Display NAME, STIPEND, SUBJECT of those students whose name starts with ‘R’
Ans: select NAME, STIPEND, SUBJECT from GRADUATE where NAME like ‘R%’ ;
iii) To count the number of students who are either PHYSICS or COMPUTER SC
graduates.
INSERT INTO MOVIE VALUES(1, ‘Gone with the Wind’, ’Drama’, ‘G’, ‘Gable’, 4, 39.95) ;
(i) Display a list of all movies with Price over 20 and sorted by Price.
(iii) Display Title, Type for all movies where Rating is ‘R’.
(iv) Find the total no of the movie title available in the library.
(i) To display details of those games which are having PrizeMoney more than 7000.
(ii) To display the content of the GAMES table in ascending order of ScheduleDate.
(iii) To display sum of PrizeMoney for each of the Number of participation groupings
(as shown in column Number 2 or 4)
(iv) Display all information about the ‘Carom Board’ from the above table.
(ii) To display the details of Item whose Price is in the range of 35000 to 55000 (Both values
included).
Ans: Select * from Item Where Price between 35000 and 55000;
(iii) To display the CustomerName, City from table Customer, and ItemName and Price from
table Item, with their corresponding matching I_ID.
Ans: Select CustomerName, City, ItemName, Price from Item, Customer where
Item.I_ID=Customer.I_ID;
iv) To increase the Price of all Items by 1000 in the table Item.
Ans: Update Item
set Price=Price+1000;
Ans: City
Delhi
Mumbai
Bangalore
N.Roy PQR
H.Singh XYZ
R.Pandey COMP
C.Sharma PQR
K.Agarwal ABC
(viii) SELECT ItemName, Price * 100 FROM Item WHERE Manufacturer = ‘ABC’;
(i) Display NAME of all doctors who are in “MEDICINE” having more than 10 years experience from
the Table DOCTOR.
(ii) Display the average salary of all doctors working in “ENT”department using the tables. DOCTORS
and SALARY Salary =BASIC+ALLOWANCE.
(iv) Display the highest consultation fee among all male doctors.
Table: FLIGHT
Table: FARES
FL_NO AIRLINES FARE TAX%
(i) Display FL_NO and NO_FLIGHTS from “KANPUR” TO “BANGALORE” from the table FLIGHTS.
(ii) Arrange the contents of the table FLIGHTS in the ascending order of FL_NO.
Ans: Select FL_NO, FARE+FARE+(TAX%/100) from FLIGHTS, FARES where Starting=”DELHI” AND
Ending=”MUMBAI”;
iv) Display the minimum fare “Indian Airlines” is offering from the tables FARES.
Ans: AVG(FARE)
7400
Ans:
SELECT * FROM CUSTOMER WHERE Connection = ‘Bsnl’ OR Connection = ‘Airtel’ ORDER BY
Activation_date;
Ans:
UPDATE CUSTOMER
SET Amount = Amount – 500
WHERE Connection=’ Reliance’;
(iii) Count the no. of companies giving connection from CUSTOMER table whose name starts
with ‘P’.
Ans:
SELECT COUNT(*) FROM CUSTOMER WHERE Cname LIKE ‘P%’;
(iv) To display the ID and Cname from table Customer and Make from table Mobile,
with their corresponding matching ID.