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

MYSQL

mysql commands

Uploaded by

Vansh Bhatia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

MYSQL

mysql commands

Uploaded by

Vansh Bhatia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

MYSQL

UNSOLVED QUESTIONS

Q21 Consider the following tables WORKER and PAYLEVEL


and answer the questions:

Table: WORKER

ECODE NAME DESIG PLEVEL DOJ DOB

11 Sachin Patel Supervisor P001 13-09-2004 23-08-1985

Chander
12 Operator P003 22-02-2010 12-07-1987
Nath

13 Fizza Operator P003 14-06-2009 14-10-1983

Ameen
15 Mechanic P002 21-08-2006 13-03-1984
Ahmed

18 Sanya Clerk P002 19-12-2005 09-06-1983


Table: PAYLEVEL

PLEVEL PAY ALLOWANCE

P001 26000 12000

PO02 22000 10000

P003 12000 6000

(a)To display details of all workers in descending order of DOB.


b) To display the PLEVEL and number of workers in that PLEVEL.

(c) To display the PLEVEL and number of workers in that PLEVEL


whose pay is greater than 15000.

(d) to display NAME and DESIG of those workers, whose PLEVEL is


either P001 or P002.

(e) Give the output of the following SQL queries:

(i) select count(PLEVEL), PLEVEL from WORKER group by


PLEVEL;
(ii) select max(DOB), min(DOB) from WORKER;

Q22 Consider the tables given below and answer the questions
that follow:

Table: EVENT

Eventid Event NumPerformers CelebrityID

101 Birthday 10 C102

102 PromotionParty 20 C103

103 Engagement 12 C102

104 Wedding 15 C104


Table: CELEBRITY
CelebritylD CelebrityName Phone FeeCharged

C101 FaizKhan 9910195676 200000

C102 Sanjaykumar 8934664482 250000

C103 NeeraKhanKapoor 9811665686 300000

C104 ReenaBhatia 7087775650 100000

(a) Name the Primary keys in both the tables and the Foreign key in
'Event' table. Can NumPerformers (Number of performers) be set as
the Primary key? Give reason.

ANS Primary Key in Event table :- EventID


Primary Key in Celebrity table :- CelebrityID
Foreign key in Event Table :- CelebrityID

NumPerformer will never a primary key because it can have duplicate


value but primary key always have unique value.
(b) How many rows will be present in the Cartesian join of the
above-mentioned two tables?

ANS 4 * 4 = 16
(c) Write the commands in SQL:

(i) To display Eventld, Event name, Celebrityld for only those events
that have more than 10 performers.
(ii) To display Celebrityld and names of celebrities who have
"Khan" anywhere in their names.

(iii) To display names of celebrities and fee charged for those


celebrities who charge more than 200000.

Q23 Consider the following structure of TEACHER and


STUDENT table:

Table: TEACHER
TeacherID TName City Subject Qualification Designation
Table: STUDENT

TeacherID
StdID Name FName Stream

Write the SQL commands to get the following:


(a) Show the name of students enrolled in Science stream.

(b) Count the number of students in Commerce stream.

(c) Count the number of teachers in each designation.

(d) Display the maximum pay of teacher who is teaching English.

(e) Display the names of students who are taught by "Anand

Mathur".

(f) Display the names and designations of teachers who are


teaching a student named "Amit".
(g) Find out the name of the teacher who is getting the highest pay.

(h) Find out the cities of teachers who are teaching Maths.

(i) Find out the name of teacher who is getting the lowest salary
among PGTS.

(j) Display the list of students who are taught by PGTs only.
Q24 Consider the following table and answer the questions
that follow.

Table: TEACHER2

ID Name Department Hiredate Category Gender Salary

1 Tanya Nanda SocialStudies 1994-03-17 TGT F 25000

2 Saurabh Sharma Art 1990-02-12 PRT M 20000

3 Nandita Arora English 1980-05-16 PGT F 30000

4 James Jacob English 1989-10-16 TGT M 25000

5 Jaspreet Kaur Hindi 1990-08-01 PRT F 22000

6 Disha Sehgal Math 1980-03-17 PRT F 21000

7 Sonali Mukherjee Math 1980-11-17 TGT F 24500

Write the command/output for the following:


(a) To display all information about the teacher of PGT category.

(b) To list the names of female teachers of Hindi department.

(c) To list names, departments and date of hiring of all the teachers
in ascending order of date of joining.

(d) To count the number of teachers in English Department.


(e) Display the department and hire date of all the female teachers
whose salary is more than 25000.

(f) Display the list of teachers whose name starts with J.

(g) select count(*) from TEACHER where Category='PGT';

(h) select avg(salary) from TEACHER group by Gender;


Q25 Write SQL commands for the following on the basis of
given table SPORTS:

table SPORTS:

StudentNo Class Name Game1 Grade1 Game2 Grade2

10 7 Sameer Cricket B Swimming A

11 8 Sujit Tennis A Skating C

12 7 Kamal Swimming B Football B

13 7 Veena Tennis C Tennis A

14 9 Archana Basketball A Cricket A

15 10 Arpit Cricket A Athletics C

(a) Display the names of the students who have grade 'A' in either
Game1 or Game2 or both.
(b) Display the number of students having game 'Cricket'.

(c) Display the names of students who have the same game for
both Game1 and Game2.

(d) Display the games taken by the students whose name starts
with 'A'.

(e) Give the output of the following sql statements:


(i) select count(*) from SPORTS;
(ii) select distinct Class from SPORTS;

(iii) select max(Class) from SPORTS;

(iv) select count(*) from SPORTS group by Game1;


Q26 Consider the following table:

Table: ITEM

Itemno Iname Price Quantity

101 Soap 50 100

102 Powder 100 50

103 Face cream 150 25

104 Pen 50 200

105 Soap box 20 100

Write queries based on the table ITEM:


(a) Display the information of all the items.
(b) Display item name and price value.

(c) Display soap information.

(d) Display the item information whose name starts with letter 's'.

(e) Display a report with item number, item name and total price
(total price = price * quantity).
(f) select distinct price from item;

(g) select count(distinct price) from item;

You might also like