SQL Question Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Assignment-1

1) Consider a database LOANS with the following table


Table: LOANS
AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest
1 R.K.Gupta 300000 36 12.00 19-07-2009 1200
2 S.P.Sharma 500000 48 10.00 22-03-2008 1800
3 K.P.Jain 300000 36 NULL 08-03-2007 1600
4 M.P.Yadav 800000 60 10.00 06-12-2008 2250
5 S.P.Sinha 200000 36 12.50 03-01-2010 4500
6 P. Sharma 700000 60 12.50 05-06-2008 3500
7 K.S.Dhall 500000 48 NULL 05-03-2008 3800

Answer the following questions.


a) Display the sum of all loan amount whose interest rate is greater than 10.
b) Display the maximum interest from loans table.
c) Display the count of all loan holders whose name ends with ‘sharma’.
d) Display the count of all loan holders whose interest is NULL.
e) Display the interest wise details of loan account holders.
a) Display the interest wise details of loan account holders with at least 10 instalments
remaining.
a) Display the interest wise count of all loan holders whose instalment due is more than 5 in
each group.

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

ACode ActivityName ParticipantsNum PrizeMoney ScheduleDate


1001 R.K.Gupta 16 36 12.00
1002 S.P.Sharma 10 48 10.00
1003 K.P.Jain 12 36 NULL
1005 M.P.Yadav 12 60 10.00
1008 S.P.Sinha 10 36 12.50
Table: COACH

PCode Name ACode


1 Ahmad Hussain 1001
2 Ravinder 1008
3 Janila 1001
5 Naaz 1003

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

VCODE VEHICLETYPE PERKM


V01 VOLVO BUS 150
V02 AC DELUXE BUS 125
V03 ORDINARY BUS 80
V05 SUV 30
V04 CAR 18

Table: TRAVEL

CNO CNAME TRAVELDATE KM VCODE NOP


101 K.Niwal 2015-12-13 200 V01 32
103 Fedrick Sym 2016-03-21 120 V03 45
105 Hitesh jain 2016-04-23 450 V02 42
102 Ravi Anish 2016-01-13 80 V02 40
107 John Malina 2015-02-10 65 V04 2
104 Sahanubhuti 2016-01-28 90 V05 4
106 Ramesj Jaya 2016-04-06 100 V01 25

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

CODE GENDER DESIGNATION


1001 MALE VICE PRINCIPAL
1009 FEMALE COORDINATOR
1203 FEMALE COORDINATOR
1045 MALE HOD
1123 MALE SENIOR TEACHER
1167 MALE SENIOR TEACHER
1215 MALE HOD

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

TCODE TTYPE PERKM


103 ORDINARY BUS 90
105 SUV 40
104 CAR 20
103 ORDINARY BUS 90
101 VOLVO BUS 160
102 AC DELUXE BUS 140

Table: TRIP

NO NAME TDATE KM TCODE NOP


11 TANISH KHAN 2015-12-13 200 101 32
13 DANISH SAHAI 2016-06-21 100 103 45
15 RAM KUMAR 2016-02-23 350 102 42
12 FEN SHEN 2016-01-13 90 102 40
17 AAN KUMAR 2015-02-10 75 104 2
14 VEENA 2016-06-28 80 105 4
16 RAJPAL KIRTI 2016-06-06 200 101 25

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

CID NAME CITY PRODUCTNAME


111 SONY DELHI TV
222 NOKIA MUMBAI MOBILE
333 ONIDA DELHI TV
444 SONY MUMBAI MOBILE
555 BLACKBERRY MADRAS MOBILE
666 DELL DELHI LAPTOP

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

Watchid Watch_Name Price Type Qty_store


W001 High Time 10000 Unisex 100
W002 Life Time 15000 Ladies 150
W003 Wave 20000 Gents 200
W004 High fashion 7000 Unisex 250
W005 Golden Time 25000 Gents 100

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

(a) Write the SQL queries:


1. To display Name and Price of all the Accessories in ascending order of their Price.
2. To display Id and SName of all Shop located in Nehru Place.
3. To display Minimum and Maximum Price of each Name of Accessories.
4. To display Name, Price of all Accessories and their respective SName where they are
available.
(b) Write the output of the following SQL
1. SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE> =5000;
2. SELECT AREA, COUNT(*) FROM SHOPPE GROUP BY AREA;
3. SELECT COUNT (DISTINCT AREA) FROM SHOPPE;
4. SELECT NAME, PRICE*0.05 DISCOUNT FROM ACCESSORIES WHERE SNO IN (‘S02‘,S03‘);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy