0% found this document useful (0 votes)
90 views

DBMS

The document contains 7 questions with SQL queries and tables. The questions involve retrieving data from the tables by joining tables, filtering on conditions, sorting, aggregating and performing calculations. Sample outputs are also provided for some queries to help write the SQL and understand the problem better. The tables contain data about employees, departments, customers, orders, books, workers, pay levels, shops and accessories.

Uploaded by

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

DBMS

The document contains 7 questions with SQL queries and tables. The questions involve retrieving data from the tables by joining tables, filtering on conditions, sorting, aggregating and performing calculations. Sample outputs are also provided for some queries to help write the SQL and understand the problem better. The tables contain data about employees, departments, customers, orders, books, workers, pay levels, shops and accessories.

Uploaded by

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

1.

Write SQL queries for (i) to (iv) and write output for SQL queries (v) to (viii),
which are based on the tables.
Table : EMPLOYEE
ENO NAME DOJ DOB GENDER DCODE
1001 Kshitij 2013-09-02 1991-09-01 Male D01
1002 Kirti Dubey 2012-12-11 1990-12-15 Female D03
1003 Deepak 2013-02-03 1987-09-04 Male D05
1007 Anil Jha 2014-01-17 1984-10-19 Male D04
1004 Jatinder 2012-12-09 1986-11-14 Female D01
1005 Somesh 2013-11-18 1987-03-31 Male D02
1006 Jaya Priya 2014-06-09 1985-06-23 Female D05

Table : DEPT
DCODE DEPARTMENT LOCATION
D01 INFRASTRUCTURE DELHI
D02 MARKETING DELHI
D03 MEDIA MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI

(i) To display Eno, Name, Gender from the table EMPLOYEE in ascending order
of ENo.
(ii) To display the name of all the male employees from the table EMPLOYEE.
(iii) To display the Eno and Name of those employees from the table EMPLOYEE
who have born between ‘1987-01-01’ and ‘1991-12-01’
(iv) To count and display FEMALE employees who have joined after ‘1986-01-01’.

(v) SELECT COUNT(*), DCODE FROM EMPLOYEE


GROUP BY DCODE HAVING COUNT(*)>1;
(vi) SELECT NAME, DEPARTMENT FROM EMPLOYEE E, DEPT D
WHERE E. DCODE=D.DCODE AND ENO<1003;

(vii) SELECT DISTINCT DEPARTMENT FROM DEPT;

(viii) SELECT MAX(DOJ), MIN (DOB) FROM EMPLOYEE;

2. Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii)
which are based on the tables.
Table : EMPLOYEE
ECODE NAME Gender DESIGNATION PLEVEL DOB
785 Sonali F Supervisor P09 1989-10-19
568 Amrita F Operator P06 1994-06-07
256 Ankit M Mechanic P07 1991-11-27
123 Sayani F Clerk P06 1998-07-20
981 Gaurav M Mechanic P07 1995-02-03

Table : PAYMENT
PLEVEL PAY ALLOWANCE
P06 29000 3500
P07 32000 4500
P09 40000 6000

a. Display the NAME and DESIGNATION of those female Employees whose pay
level is P06.
b. Display name of employees whose name has letter ‘a’ as the second
character.
c. To display the name of those employees whose age is between 01-01-1992
and 31-12-1996.
d. Display name of all employees in alphabetic order.

e. SELECT COUNT(PLEVEL), PLEVEL FROM EMPLOYEE GROUP BY PLEVEL;


f. SELECT MAX(DOB), MIN(DOB) FROM EMPLOYEE;
g. SELECT PLEVEL, PAY+ALLOWANCE FROM PAYMENT WHERE PLEVEL= ‘P07’;
h. SELECT DISTINCT(DESIGNATION) FROM EMPLOYEE;
3. Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii)
which are based on the tables.
Table: CUSTOMER
CUST_ID CNAME GENDER CTYPE CITY
C01 Hemlata F Prime Jaipur
C05 Saurav M Regular Nagpur
C06 Amar Rai M Prime Surat
C25 Shivani F Regular Guwahati
C41 Devendra M Regular Jaipur
C39 Harshali F Regular Vadodara

Table: ORDER
ORDER_ID PRODUCT QTY AMOUNT ORDERDATE CUST_ID
2856 TV 1 32000 2020-10-07 C05
4213 Mobile 2 26000 2020-11-28 C25
1220 Fan 3 6000 2019-01-05 C39
7895 Refrigerator 1 30000 2022-01-29 C05
6542 TV 2 70000 2021-04-04 C25

Write SQL query for (i) to (iv)


(i) To show orde ID, Product name and quantity of those orders which have the
quantity more than 1.
(ii) To show Product name, Amount and Customer name of those customers
who lives in Nagpur city.
(iii) To Display each type of customer and their numbers from customer table.
(iv) To show the details of all orders in descending order of their order date.

Write output of the following (v) to (viii):


(v) SELECT MIN(AMOUNT) FROM ORDER WHERE QTY !=3;
(vi) SELECT AVG(AMOUNT) FROM ORDER WHERE ORDERDATE> “2020-01-01”;
(vii) SELECT CNAME, GENDER CTYPE FROM CUSTOMER WHERE CNAME LIKE “%i”
AND CTYPE= “Regular”;
(viii) SELECT DISTINCT PRODUCT FROM ORDER WHERE AMOUNT>10000;
4. Write the SQL query commands based on following table
Table : BOOK
Book_Id BookName Author Publisher Price Genre Qty
9788 Geetanjali R. N. Thakur Rajkamal 199 Poetry 5
9789 Godan Premchand Maple 195 Fiction 20
4166 Deepshikha Mahadevi Vani 300 Poetry 10
5520 2States Chetan Rupa 250 Fiction 15
4772 Kamayani J. S. Prasad Maple 125 Classic 50

Table : ISSUED
Book_Id Qty_Issued
4166 4
9788 2
4772 2

Write SQL query for (i) to (iv)


a. To show book name, Author name and price of books of Maple publisher.
b. To show name of books of Poetry genre.
c. To Display the name and price of books in ascending order of their price.
d. To increase the price of all books of Vani publishers by 50.

Write output of the following (v) to (viii):


e. Select count(*) from Book;
f. Select max(Price) from book where Qty >=15;
g. Select BookName, Publisher from book where Genre= “Fiction”;
h. Select count(distinct publisher) from book where Price>=400;

5. Consider the following tables WORKER and PAYLEVEL and answer questions (i) to
(viii) of this question:
Table: WORKER
ECODE NAME DESIG PLEVEL DOJ DOB
11 Mayank Shah Supervisor P001 2015-01-12 1990-12-13
12 Gaurav Shah Operator P003 2017-07-07 1992-09-28
13 Sudha Sharma Operator P003 2016-10-04 1992-02-13
15 Sangeeta Sinha Mechanic P002 2017-06-22 1993-10-09
18 Hanumant Patel Clerk P002 2015-08-25 1994-05-19

Table: PAYLEVEL
PLEVEL PAY ALLOWANCE
P001 36000 12000
P002 28000 10000
P003 9000 6000

Write SQL Queries for the following (i) to (iv)


(i) To display the details of all workers in descending order of DOB.
(ii) To display Name and Designation of those workers whose PLEVEL is
either P001 or P002.
(iii) To display the content of all workers whose DOB is between “19-JAN-1990‟
and 18-OCT-1992‟.
(iv) To add a new row with the following data :19, “Jayant Saini”, “Operator‟,
“P003”. “19-Jun-2018‟, “11-Jul-1995”.

Write output for the following (v) to (viii):

(v) SELECT COUNT (PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;


(vi) SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
(vii) SELECT NAME, PAY FROM WORKER W, PAYLEVEL P WHERE W.PLEVEL =
S.PLEVEL AND P.ECODE<13;
(viii) SELECT PLEVEL, PAY+ALLOWANCE FROM PAYLEVELWHERE PLEVEL =
“P003”;

6.

(a) Consider the following tables SHOPPE and ACCESSORIES and answer the
questions (i) to (viii):
Table: SHOPPE
ID SNAME AREA
S001 ABC Computronics Akota
S002 All Infotech Media Makarpura
S003 Tech Shop Manjalpur
S004 Geeks Techno Soft Manjalpur
S005 Hitech Tech Store Makarpura

Table: ACCESSORIES
ItemNo Name Price ID
A01 Mother Board 12000 S001
A02 Hard Disk 5000 S004
A03 Keyboard 600 S005
A04 Mouse 300 S001
A05 Mother Board 10000 S002
A06 Keyboard 700 S002
A07 Monitor 4500 S003
A08 Monitor 5500 S004
A09 Mouse 500 S002
A10 Hard Disk 3500 S001

Write SQL Queries (i) to (iv):


(i) To display name and price of all the accessories in descending order of their
price.
(ii) To display ID and SNAME of all shops located in Manjalpur area.
(iii) To display minimum and maximum price of each name of accessories.
(iv) To display name and price of all accessories and their respective SNAME
where they are available.
Write output for the following SQL Queries (v) to (viii):
(v) SELECT DISTINCT NAME FROM ACCESSORIES WHERE PRICE>=5000;
(vi) SELECT AREA, COUNT(*) FROM SHOPPE GROUP BY AREA;
(vii) SELECT COUNT(DISTINCT AREA) FROM SHOPPE;
(viii) SELECT NAME, PRICE*2 FROM ACCESSORIES WHERE ID IN (‘S001’,
‘S004’);
Q.7
(a) Consider the following tables CARDEN and CUSTOMER and answer the questions
(i) to (viii):
Table: CARDEN
CODE CarName Make Colour Capacity Charges
501 A-Star Suzuki Red 3 14
503 Indigo Tata Silver 3 12
502 Innova Toyota White 7 15
509 Verna Hyundai Silver 4 17
510 Creta Hyundai Red 4 20

Table: CUSTOMER
CNO CNAME CODE
C05 Shilpi Ramteke 503
C18 Deepali Shah 509
C06 Priyakshi Yadav 502
C11 Sonam Deshkar 510

Write SQL commands for the following statements:


(i) To display the names of all silver colour cars.
(ii) To display name of car, make and capacity of cars in descending order of
their sitting capacity.
(iii) To display the highest charges at which a vehicle can be hired
from CARDEN.
(iv) To display the customer name and corresponding name of the cars hired by
them.
Write output of the following SQL queries:
(v) SELECT COUNT(DISTINCT Make) FROM CARDEN;
(vi) SELECT MAX(Charges), MIN(Charges) FROM CARDEN;
(vii) SELECT Make, COUNT(*) FROM CARDEN;
(viii) SELECT CarName FROM CARDEN WHERE Capacity=4;

Q.8
(a) Expand the following:
(i) SQL (ii) RDBMS

(b) Which function do we use with cursor object to write and run SQL query in Python
and MySQL database connectivity?

(c) Consider the following table named as EMPLOYEE.


Table : EMPLOYEE
ENO NAME Salary DOB GENDER DEPT
1001 Ankit 25000 1992-09-01 Male HR
1002 Saloni 60000 1991-12-15 Female R&D
1003 Sanjay 40000 1988-09-04 Male HR
1007 Harish 42000 1985-10-19 Male Production
1004 Sunita 30000 1987-11-14 Female Production
1005 Ashok 25000 1988-03-31 Male HR
1006 Namita 50000 1986-06-23 Female Production
Write SQL queries for (i) to (iv):
(i) To display Eno, Name, Gender in ascending order of ENo.
(ii) To display the name of all the female employees.
(iii) To display the Eno and Name of those employees who are born between
‘1988-01-01’ and ‘1992-12-01’.
(iv) Display the average salary of each gender.

Find outputs for SQL queries (v) to (viii):


(v) SELECT COUNT(*) FROM EMPLOYEE
GROUP BY DEPT HAVING COUNT(*)>1;
(vi) SELECT DISTINCT DEPT FROM EMPLOYEE;
(vii) SELECT MAX(DOB), MIN (DOB) FROM EMPLOYEE;
(viii) SELECT NAME, SALARY, DEPT FROM EMPLOYEE WHERE NAME LIKE
“_a%”;

Q.9
(a) Write difference between fetchone( ) and fetchall( ) in respect of database.

(b) Consider the following table named as STAFF.

Table : STAFF
ENO NAME Salary DOB GENDER DEPT
E01 Harsh 26000 1992-09-01 Male Marketing
E02 Divya 52000 1991-12-15 Female Marketing
E03 Sujata 41000 1988-09-04 Female HR
E04 Meenal 32000 1985-10-19 Female Production
E05 Akanksha 22000 1987-11-14 Female IT
E06 Arun 15000 1988-03-31 Male IT
E07 Sharmila 10000 1986-06-23 Female Production
Write SQL queries for (i) to (iv):

(i) To display Eno, Name, Gender in descending order of ENo.

(ii) To display the name of all the female staff whose name starts with the
letter ‘N’.

(iii) To display the Eno, Name and salary of those employees whose salary
between 27000 and 36000.

(iv) Display name of departments without repeating the value of


departments.

Write outputs of the SQL queries (v) to (viii) based on the relations
PLAYER and GAME given below:

TABLE: PLAYER
Pcode Pname Gender DOB State Gcode
401 Ravita F 2000-10-09 Punjab 03
402 Gauravi F 2001-01-22 Bihar 02
403 Rakesh M 2000-11-29 Haryana 01
404 Divya F 2002-05-12 Rajasthan 02
405 Hemali F 2000-09-21 Gujarat 01
406 Ashok M 2000-12-12 Rajasthan 03

TABLE: GAME
Gcode Gname no_of_players Gtype
01 Tennis 1 Outdoor
02 Cricket 11 Outdoor
03 Badminton 1 Indoor

(v)SELECT Gtype, count(*) FROM GAME GROUP BY Gtype;


(vi) SELECT Max(DOB), Min(DOB) FROM PLAYER;
(vii) SELECT PLAYER.Pname, PLAYER.State, GAME.Gname WHERE
PLAYER.Gcode=GAME.Gcode and Gender= “F”;
(viii) SELECT Pname, Gender, State FROM PLAYER WHERE State= “Rajasthan”
and Gcode=02;
Q.10
(a) Define the following:
(i) Attribute (ii) Key
(b) Consider the following table DRESS. Write SQL commands for the following
statements.
Table: DRESS
DCODE DESCRIPTION PRICE MCODE LAUNCHDATE
10001 Formal Shirt 1250 M001 12-JAN-08
10020 Frock 750 M004 09-SEP-07
10012 Informal Shirt 1450 M002 06-JUN-08
10019 Party Wear 1500 M003 06-JUN-08
10090 Tulip Skirt 850 M002 31-MAR-07
10023 Pencil Skirt 1250 M003 19-DEC-08
10089 Slacks 850 M003 20-OCT-08
10007 Formal Pant 1450 M001 09-MAR-08
10009 Informal Pant 1400 M002 20-OCT-08
10024 Baby Top 650 M003 07-APR-07

(i) To display DCODE and DESCRIPTION of each dress in ascending order of


DCODE.
(ii) To display the details of all the dresses which have LAUNCHDATE in
between 05-DEC-07 and 20-JUN-08 (inclusive of both the dates).
(iii) To display the average PRICE of all the dresses which are made up of
material with MCODE as M003.
(iv) To display material wise (MCODE) highest and lowest price of dresses from
DRESS table.

Consider the following tables GAMES and PLAYER and answer the
following parts:
Table: GAMES
Gcode GameName Type Number PrizeMoney ScheduleDate
101 Carom Board Indoor 2 5000 23-01-2004
102 Badminton Outdoor 2 12000 12-12-2003
103 Table Tennis Indoor 4 8000 15-02-2004
105 Chess Indoor 2 9000 01-01-2004
108 Lawn Tennis Outdoor 4 25000 19-03-2004

Table: PLAYER
Pcode Name Gcode
1 Atul Sharma 101
2 Pradeep Mishra 108
3 Manish Tripathi 101
4 Harish Goyal 103
Give the output of the following SQL queries:

(v) SELECT COUNT(DISTINCT Number) FROM GAMES;

(vi) SELECT MAX(ScheduleDate), MIN(ScheduleDate) FROM GAMES;

(vii) SELECT Name, GameName FROM GAMES G, PLAYER

P WHERE G.Gcode=P.Gcode and

G.PrizeMoney>10000;

(viii) SELECT DISTINCT Gcode FROM PLAYER;

You might also like