0% found this document useful (0 votes)
175 views16 pages

12 (19-2-1) Ques DBMS (SQL QUERIES)

Uploaded by

ballabhkharvesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views16 pages

12 (19-2-1) Ques DBMS (SQL QUERIES)

Uploaded by

ballabhkharvesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1.

Select avg(exp) from staff where gender = ‘F’;


2. Select min(doj) from staff;
3. Select *from staff where gender!=’M’ and dept like ‘ ’;
4. Select name, doj from staff where dept not in (‘Finance’,’Sales’);
Table: TRAINER
TrainerNo Name City HireDate Salary
101 SUNAINA MUMBAI 1998-10-15 90000
102 ANAMIKA DELHI 1994-12-24 80000
103 DEEPTI CHANDIGARH 2001-12-21 82000
104 MEENAKSHI DELHI 2002-12-25 78000
105 RICHA MUMBAI 1996-01-12 95000
106 MANIPRABHA CHENNAI 2001-12-12 69000
1. Can City be used as Primary key for table TRAINER? Justify your answer.

2. What is the degree and cardinality of the table TRAINER? If we add two
rows and remove three rows from table TRAINER. Also if we add another
attribute in the table, what will be the degree and cardinality of the table
TRAINER will become?

3. a. Insert a new record in table TRAINER with values, TrainerNo =1 107, Name =
Swastik, HireDate = 1999-01-22, Salary = 90000.
b. Increase the salary of those Trainer having city as DELHI by 5000.
c. Removes those records from table TRAINER who were hired after 1 -1-2000.
d. Add a new column Grade with datatype as Varchar and maximum 1 size as 2.
TABLE: ELECTRONICS

Item_ID IName Manufaturing_Date Make Qty Price

IT026 Refrigerator 2019-12-15 Samsung 15 16000

IT039 TV 2020-06-25 Samsung 7 28000

IT088 Computer 2020-01-30 Acer 15 44000

IT054 TV 2022-02-16 Sony 10 15000

IT061 Computer 2021-11-17 IFB 12 21000

1. Select COUNT(*), Make From Electronics Group by


Make Having COUNT(*)>1;
2. Select Max(Manufacturing_Date), Min(Price) From
Electronics;
3. Select Item_ID, IName From Electronics Where
IName like “%sh%”;
4. Select Avg(Price) From Electronics Where Qty > 10;
• what will be the degree and
cardinality of the resulting
relation after Cartesian
product of above relations?

• what will be the degree and


cardinality of the resulting
flight after addition of two
rows and deletion of one
column?
• (i) Write a query to display the
NAME, corresponding FARE
and F_DATE
• of all PASSENGERS who
have a flight to START from
DELHI.
• (ii) Write a query to delete the
records of flights which end at
Mumbai.
• OR
• (c) create a new table traveller
having same fields and tuples
as passenger.
Consider the following tables and answer the questions a and b:
Table: Garment What will be output of the following
GCode GName Rate Qty CCode command:
G101 Saree 1250 100 C03 1. SELECT * FROM GARMENT
G102 Lehanga 2000 100 C02
NATURAL JOIN CLOTH;
G103 Plazzo 750 105 C02
2. SELECT DISTINCT QTY FROM
G104 Suit 2000 250 C01
G105 Patiala 1850 105 C01
GARMENT;
3. SELECT SUM(QTY)
Table: Cloth FROMGARMENT GROUP BY
CCode CName CCODE HAVING COUNT(*)>1;
C01 Polyester
C02 Cotton 4. SELECT GNAME, CNAME, RATE
C03 Silk
FROM GARMENT G,CLOTH C
C04 Cotton-
Polyester
WHERE G.CCODE = C.CCODE AND
QTY>100;

5. SELECT AVG(RATE) FROM


GARMENT WHERE RATE BETWEEN
1000 AND 2000;
Table: CLUB
CoachID CoachNam Ag Sports Dateofapp Pay Sex
1. To list names of all
coaches with their date of
e e
appointment in
1 KUKREJA 35 KARATE 1996-03-27 1000 M
2 RAVINA 34 KARATE 1998-01-20 1200 F
descending order.
3 KARAN 34 SQUASH 1998-02-19 2000 M
4 TARUN 33 BASKETBALL 1998-01-01 1500 M 2. To display total pay given
5 ZUBIN 36 SWIMMING 1998-01-12 750 M to coaches in each sport.
6 KETAKI 36 SWIMMING 1998-02-24 800 F
7 ANKITA 39 SQUASH 1998-02-20 2200 F 3. SELECT Sportsperson,
8 ZAREEN 37 KARATE 1998-02-22 1100 F Coachname FROM Club,
9 KUSH 41 SWIMMING 1998-01-13 900 M Coaches WHERE Coachid=
10 SHAILYA 37 BASKETBALL 1998-02-19 1700 M
Coach_no;
Table: COACHES
4. SELECT Sex,
Sportsperson Sex Coach_No MAX(Dateofapp),
AJAY M 1 MIN(Dateofapp) FROM
SEEMA F 2 Club GROUP BY Sex;
VINOD M 1
TANEJA F 3
Table: Garment
What will be output of the following
GCode GName Rate Qty CCode command:
1. SELECT * FROM GARMENT NATURAL
G101 Saree 1250 100 C03 JOIN CLOTH;
G102 Lehanga 2000 100 C02
G103 Plazzo 750 105 C02 2. SELECT DISTINCT QTY FROM GARMENT;

G104 Suit 2000 250 C01 3. SELECT SUM(QTY) FROM GARMENT


G105 Patiala 1850 105 C01 GROUP BY CCODE HAVING
COUNT(*)>1;

Table: Cloth 4. SELECT GNAME, CNAME, RATE FROM


GARMENT G,CLOTH C WHERE G.CCODE
CCode CName = C.CCODE AND QTY>100;

C01 Polyester 5. SELECT AVG(RATE) FROM GARMENT


C02 Cotton WHERE RATE BETWEEN 1000 AND 2000;
C03 Silk
C04 Cotton-Polyester
TABLE: PLAYER

Pcode Pname Gender DOB State Gcode 1. SELECT Gtype, count(*) FROM
401 Ravita F 2000-10-09 Punjab 03 GAME GROUP BY Gtype;

402 Gauravi F 2001-01-22 Bihar 02 2. SELECT Max(DOB), Min(DOB)


403 Rakesh M 2000-11-29 Haryana 01 FROM PLAYER;
404 Divya F 2002-05-12 Rajasthan 02
3. SELECT P.Pname, P.State,
405 Hemali F 2000-09-21 Gujarat 01 G.Gname FROM PLAYER P,
GAME G WHERE
406 Ashok M 2000-12-12 Rajasthan 03
P.Gcode=G.Gcode and Gender= “F”;

TABLE: GAME 4. SELECT Pname, Gtype,DOB


FROM PLAYER P, GAME G
Gcode Gname no_of_players Gtype
WHERE P.GCODE=G.GCODE and
01 Tennis 1 Outdoor State=”Rajasthan”;
Write SQL command to change the
02 Cricket 11 Outdoor
table name Game to Sports.
03 Badminton 1 Indoor
TABLE-DEPT
1. SELECT COUNT(*),DCODE FROM
DCODE DEPARTMENT CITY WORKER GROUP BY DCODE
D01 MEDIA DELHI HAVING COUNT(*)>1;
D02 MARKETING DELHI
2. SELECT DISTINCT DEPARTMENT FROM
D03 INFRASTRUCTURE MUMBAI
DEPT;
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI 3. SELECT NAME,DEPARTMENT,CITY FROM
WORKER W, DEPT D WHERE
TABLE-WORKER W.DCODE=D.DCODE AND WNO<1003;

WNO NAME DOJ DOB GENDER DCODE


1001 GEORGE K 2013-09-02 1991-09-01 MALE D01 4. SELECT MAX(DOJ),
MIN(DOB) FROM WORKER;
1002 RYMA SEN 2012-12-11 1990-12-15 FEMALE D03
1003 MOHITESH 2013-02-03 1987-09-04 MALE D05
1007 ANIL JHA 2014-01-17 1984-10-19 MALE D04
1004 MANILA SAHAI 2012-12-09 1986-11-14 FEMALE D01
1005 R SAHAY 2013-11-18 1987-03-31 MALE D02
1006 JAYA PRIYA 2014-06-09 1985-06-23 FEMALE D05
TABLE-DEPT
1. SELECT COUNT(*),DCODE FROM
DCODE DEPARTMENT CITY WORKER GROUP BY DCODE
D01 MEDIA DELHI HAVING COUNT(*)>1;
D02 MARKETING DELHI 2. SELECT DISTINCT DEPARTMENT FROM
DEPT;
D03 INFRASTRUCTURE MUMBAI 3. SELECT NAME,DEPARTMENT,CITY
D05 FINANCE KOLKATA FROM WORKER W,DEPT D
D04 HUMAN RESOURCE MUMBAI WHERE W.DCODE=D.DCODE AND
WNO<1003;
TABLE-WORKER

WNO NAME DOJ DOB GENDER DCODE 4. SELECT MAX(DOJ),


MIN(DOB) FROM WORKER;
1001 GEORGE K 2013-09-02 1991-09-01 MALE D01
1002 RYMA SEN 2012-12-11 1990-12-15 FEMALE D03 5. write the SQL command to
display all database .
1003 MOHITESH 2013-02-03 1987-09-04 MALE D05
1007 ANIL JHA 2014-01-17 1984-10-19 MALE D04 6. To show the structure of dept

1004 MANILA SAHAI 2012-12-09 1986-11-14 FEMALE D01 7. To add one more column
1005 R SAHAY 2013-11-18 1987-03-31 MALE D02 appt_date.

1006 JAYA PRIYA 2014-06-09 1985-06-23 FEMALE D05


Table: School
SELECT * FROM SCHOOL NATURAL JOIN
SID SName Fee Class CCode
TEACHER;
S101 JATIN 2000 11 C1101
S102 PARTH 1500 11 C1102 What will be the output of following
commands:
S103 SNEHA 1800 12 C1202 SELECT DISTINCT CLASS FROM
S104 PRADEEP 2750 11 C1101 SCHOOL;

S105 ABHINAV 2400 12 C1201 SELECT CCODE, SUM(FEE) FROM


Table: TEACHER SCHOOL GROUP BY
CCODE HAVING COUNT(*)>1;
CCode TName , SELECTSNAME,TNAME,

C1101 PRAMOD FROMSCHOOL S,TEACHER T


WHERE S.CCODE = T.CCODE AND
C1102 SMARAT FEE>2000;
a.SELECT AVG(FEE) AS AVGFEE
FROM SCHOOL WHERE
FEE BETWEEN 1500 AND 1800;
Table: GAMES
1. SELECT Gametype, avg(Prize)
from GAMES group by
GCode GName Number Gametype Prize Sdate Gametype;
G101 Carom 2 Indoor 15000 2022-07-02
2. SELECT max(Sdate), min (Sdate)
G102 Badminton 2 Outdoor 12000 2021-09-15 from GAMES;
G103 Table Tennis 4 Indoor 8000 2022-07-25
3. SELECT Gname, Gametype,
G104 Chess 2 Indoor 7000 2020-10-01 G.GCode, , Pname FROM
G105 Lawn Tennis 4 Outdoor 20000 2022-11-01 Games G,Player P WHERE
G.GCode=P.GCode and
Prize>10000;
Table: PLAYER
4. SELECT Gname,Pname from
PCOD PNAME GCode
Games G,Player P where
E Number>=4 and
P1 PRAMOD G101 G.GCode=P.GCode;
P2 SMARAT G102 (a) Write a Query to insert a record in to table GAMES :
P3 DIPAK G103
P4 NILESH G105 GCode GName Number Gametype Prize Sdate
G106 Chess 2 Indoor 12000 2022-10-11
Table :- PRODUCT
1. To display the details
P_ID ProductName Manufacturer Price of those Clients
TP01 Talcom Powder LAK 45 whose City is Delhi.
Fw05 Face Wash ABC 45 2. To display the details
BS01 Bath Shop ABC 55 of Products whose
SH06 Shampoo XYZ 120 Price is in the range
FW12 Face Wash XYZ 95 of 50 to 100 (Both
values included ).
Table :- CLIENT

C_ID ClientName City P_ID 3. To display the


01 Cosmetic Shop Delhi FW05 ClientName, City from
06 Total Health Mumbai BS01 table Client and
12 Live Life Delhi SH06 ProductName and Price
15 Pretty Women Delhi FW12 from table Product with
their corresponding
16 Dreams Banglore TP01
matching P_ID.
A department store MyStore is considering to maintain their inventory using SQL to store
the data . As a database administer , Abhay has decided that :-
Name of the database – mystore Name of the table - STORE
The attributes of STORE are as follows : ItemNo : numeric ItemName : Character of size 20
Scode : numeric Quantity : numeric

ItemNo ItemName Scode Quantity


2005 Sharpener Classic 23 60
2003 Ball Pen 0.25 22 50
2002 Get Pen Premium 21 150
2006 Get Pen Classic 21 250
2001 Eraser Small 22 220
2004 Eraser Big 22 110
2009 Ball Pen 0.5 21 180

1. Identify the attribute best suitable to be declared as a primary key,Write the degree
and cardinality of the table STORE .

2. Insert the following data into the attribute ItemNo, ItemName and Scode respectively
in the given table STORE ItemNo =2010, ItemName = “Note Book ” and Scode =25

3. Abhay want to remove that table STORE from the database MyStore .

4. Now Abhay wants to display the structure of the table STORE ,i.e. name of the attributes
and their respective data types that he has used in the table . Write the query to display the
same .
Table: SCHOOLADMIN

ANO NAME STREAM DOB PHONE FEE SELECT Stream, Max(FEE) FROM
101 Srishti B Business Admin 2005-05-12 12343224 2000 SCHOOLADMIN group by stream;
102 Aman Sciences 2005-11-02 67134324 4000 SELECT Max(DOB), Min(DOB) FROM
103 Shivam Sciences 2006-01-23 51134324 3500 SCHOOLADMIN WHERE
STREAM != "Sciences ";
104 Banita Business Admin 2005-10-12 13241934 2500
105 Myra Fine Arts 2005-07-01 12445931 1500
Write the command to view the
106 Raghav Humanities 2005-06-05 42155931 5000 structure of the table ‘ROADMIN’.
107 Medini Fine Arts 2005-09-05 51215931 1000
108 Udai Veer Sciences 2006-11-25 55134324 4500

Table: ROADMIN
SELECT NAME, Place FROM SCHOOLADMIN S,
R_NO STREAM PLACE ROADMIN R WHERE STREAM="Fine Arts" and
1 Sciences Agra S.Stream = R.Stream;
2 Fine Arts Jaipur
SELECT Name, Phone, R.Place, DOB FROM
3 Humanities Tinsukia SCHOOLADMIN S ROADMIN R where WHERE
S.Stream = R.Stream and ANO > 104;
Table: SHOP

Id SName Area 1. Select distinct Name from


S01 ABC Computronics CP ACCESSORIES where Price > =
S02 All Infotech Media GK II
5000;
S03 Tech Shopee CP
S04 Geek Tenco Soft Nehru Place
S05 Hitech Tech Store Nehru Place 2. Select Area, count(*) from
SHOP group by Area;
Table : ACCESSORIES Select count(distinct Area) from
No Name Price Id SHOP;
A01 Motherboard 12000 S01
A02 Hard Disk 5000 S01 3.Select A.Name , A.Price from
A03 Keyboard 500 S02 ACCESSORIES A, SHOP S where
A04 Mouse 300 S01 A.Id =S.Id and Price >=12000;
A05 Motherboard 13000 S02
A06 Keyboard 400 S03 4. write the command to create
A07 LCD 6000 S04 a database employee.
T08 LCD 5500 S05
T09 Mouse 350 S05
T010 Hard Disk 450 S03

You might also like