SQL Question Assignment
SQL Question Assignment
SQL Question Assignment
2) Consider the following tables ACTIVITY and COACH. Write SQL command for the statements
(i) to (iv) and give outputs for SQL queries (v) to (viii)
Table: ACTIVITY
a) To display the name of all activities with their ACode in descending order.
b) To display sum of PrizeMoney for each of the number of participants groupings (as shown
in column ParticipantsNum 10,12,16)
c) To display the coach’s name and ACode in ascending order of ACode from the table
COACH.
d) To display the content of the GAMES table whose ScheduleDate earlier than 01/01/2004 in
ascending order of ParticipantsNum.
e) SELECT COUNT(DISTINCT ParticipantsNum) FROM ACTIVITY;
f) SELECT MAX(ScheduleDate), MIN(ScheduleDate) FROM ACTIVITY;
g) SELECT SUM (PrizeMoney) FROM ACTIVITY;
h) SELECT DISTINCT ParticipantsNum FROM ACTIVITY;
3) Write queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on
the tables.
Table: VEHICLE
Table: TRAVEL
a) To display CNO, CNAME, TRAVELDATE from the table TRAVEL in descending order of CNO.
b) To display the CNAME of all customers from the table TRAVEL who are travelling by vechicle
with code V01 or V02
c) To display the CNO and CNAME of those customers from the table TRAVEL who travelled
between ‘2015-1231’ and ‘2015-05-01’.
d) To display all the details from table TRAVEL for the customers, who have travel distacne
more than 120 KM in ascending order of NOE
e) SELECT COUNT (*), VCODE FROM TRAVEL GROUP BY VCODE HAVING COUNT (*) > 1;
f) SELECT DISTINCT VCODE FROM TRAVEL :
g) SELECT A.VCODE, CNAME, VEHICLETYPE FROM TRAVEL A, VEHICLE B WHERE A. VCODE = B.
VCODE and KM < 90;
h) SELECT CNAME, KM*PERKM FROM TRAVEL A, VEHICLE B WHERE A.VCODE = B.VCODE AND
A. VCODE ‘V05’;
4) Consider the following tables SCHOOL and ADMIN and answer this question :
Give the output the following SQL queries :
a) Select Designation Count (*) From Admin Group By Designation Having Count (*) <2;
b) SELECT max (EXPERIENCE) FROM SCHOOL;
c) SELECT TEACHER FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY TEACHER;
d) SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
Table: School
CODE TEACHER SUBJECT DOJ PERIODS EXPERIENCE
1001 RAVI SHANKAR ENGLISH 12-03-2000 24 10
1009 PRIYA RAI PHYSICS 03-09-1998 26 12
105 LIS ANAND ENGLISH 09-04-2000 27 5
102 YASHRAJ MATHS 24-08-2000 24 15
107 GAGAN PHYSICS 16-07-1999 28 3
104 HARISH B CHEMISTRY 19-10-1999 27 5
106 UMESH PHYSICS 11-05-1998 22 16
Table: Admin
5) Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based
on the tables TRANSPORT and TRIP
Table: TRANSPORT
Table: TRIP
a) To display NO, NAME, TDATE from the table TRIP in descending order of NO.
b) To display the NAME of the drivers from the table TRIP who are traveling by transport
vehicle with code 101 or 103.
c) To display the NO and NAME of those drivers from the table TRIP who travelled between
‘2015-02-10’ and ‘2015-04-01’.
d) To display all the details from table TRIP in which the distance travelled is more than 100
KM in ascending order of NOP
e) SELECT COUNT (*), TCODE From TRIP
GROUP BY TCODE HAVNING COUNT (*) > 1;
f) SELECT DISTINCT TCODE from TRIP;
g) SELECT A.TCODE, NAME, TTYPE
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND KM < 90;
h) SELECT NAME, KM *PERKM
FROM TRIP A, TRANSPORT B
WHERE A. TCODE = B. TCODE AND A. TCODE = 105′;
6) Write SQL commands for the queries (i) to (iv) and output for (v) & (viii) based on a table
COMPANY and CUSTOMER.
Table: COMPANY
Table: CUSTOMER
CUSTID NAME PRICE QTY CID
101 ROHAN SHARMA 70000 20 222
102 DEEPAK KUMAR 50000 10 666
103 MOHAN KUMAR 30000 5 111
104 SAHIL BANSAL 35000 3 333
105 NEHA SONI 25000 7 444
106 SONAL AGGARWAL 20000 5 333
107 ARUN SINGH 50000 15 666
a) To display those company name which are having prize less than 30000.
b) To display the name of the companies in reverse alphabetical order.
c) To increase the prize by 1000 for those customer whose name starts with “S”?
d) To add one more column totalprice with decimal] 10,2) to the table customer
e) SELECT COUNT(*) , CITY FROM COMPANY GROUP BY CITY;
f) SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10;
g) SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE “%r%;
h) SELECT PRODUCTNAME,CITY, PRICE
FROM COMPANY, CUSTOMER WHERE
COMPANY. CID=CUSTOMER.CID AND
PRODUCTNAME=”MOBILE”;
7) Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on the tables
Watches’ and Sale given below.
Table: Watches
Table: Sale
Watchid Qty_Sold Qarter
W001 10 1
W003 5 1
W002 20 2
W003 10 2
W001 15 3
W002 20 3
W005 10 3
W003 15 4
a) TO DISPLAY ALL THE DETAILS OF THOSE WATCHES WHOSE NAME ENDS WITH ‘TIME’
b) TO DISPLAY WATCH’S NAME AND PRICE OF THOSE WATCHES WHICH HAVE PRICE RANGE
IN BE-TWEEN 5000-15000.
c) TO DISPLAY TOTAL QUANTITY IN STORE OF UNISEX TYPE WATCHES.
d) TO DISPLAY WATCH NAME AND THEIR QUANTITY SOLD IN FIRST QUARTER;
e) SELECT MAX (PRICE), MIN(QTY_STORE) FROM WATCHES;
f) SELECT QUARTER, SUM(QTY SOLD) FROM SALE GROUP BY QUARTER;
g) SELECT WATCH_NAME, PRICE, TYPE FROM WATCHES W, SALE S WHERE W.
WATCHID=S.WATCHID;
h) SELECT WATCH_NAME, QTYSTORE, SUM (QTY_SOLD), QTY_STORESUM (QTYSOLD)
“STOCK” FROM WATCHES W, SALE S WHERE W. WATCHID = S.WATCHID GROUP BY
S.WATCHID;
8) Answer the questions (a) and (b) on the basis of the following tables SHOP and ACCESSORIES.
Table: SHOP
ID SNAME AREA
S01 ABC computronics CP
S02 All Infotech media GK II
S03 Tech Shop CP
S04 Geeks Tecno Soft NEHRU PLACE
S05 Hitech Tech Store NEHRU PLACE
Table: ACCESSORIES
No NAME PRICE ID
A01 MOTHER BOARD 12000 S01
A02 HARD DISK 5000 S01
A03 KEYBOARD 500 S02
A04 MOUSE 30 S01
A05 MOTHER BOARD 13000 S02
A06 KEYBOARD 400 S03
A07 LCD 6000 S04
T08 LCD 5500 S05
T09 MOUSE 350 S05
T10 HARD DISK 4500 S03