0% found this document useful (0 votes)
20 views31 pages

MySQL Tables

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)
20 views31 pages

MySQL Tables

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/ 31

Table - 1

Q1. Observe the table given below (Shoppe)


Write command of SQL for (i) to (iv) and output for (v) to (viii).

i. To display names of the items whose name starts with ‘C’ in


ascending order of Price.

ii. To display code, Item name and City of the products whose
quantity is less than 100.

iii. To count distinct company name from the table.

1
iv. To insert a new row in the table Shoppe

110, “Pizza”, “Papa Jones”, 120, “Kolkata”, 50.00

v. SELECT Item from Shoppe


WHERE Item IN ("Jam”, “Coffee”);

vi. SELECT COUNT(DISTINCT(City)) from Shoppe;

2
vii. SELECT MIN(Qty) from Shoppe
WHERE City=”Mumbai”;

viii. SELECT AVG(Price) from Shoppe;


WHERE Qty>100;

3
Table - 2
Q2. Observe the table given below (EMPLOYEE)
Write command of SQL for (i) to (vi) and output for (vii) to (viii).

(i) To display names of the employees, salary, new salary from


himayatnagar branch.

(ii) To display branch wise count of the employees.

4
(iii) To display the name of the employee having unique branch.

(iv) To display the name and em_id of the employee having the least
date of joining.

(v) To display the names of the employees having a date of joining


less than 2018.

(vi) To display gender wise maximum salary.

5
(vii) SELECT BRANCH,MAX(SALARY) FROM EMPLOYEE GROUP BY
BRANCH HAVING DOJ<=2018-18-18.

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

6
Table - 3

Q3. Observe the table given below (Hospital)


Write command of SQL for (i) to (iv) and output for (v) to (viii).

(i) To list the names and age of female patients who are in
orthopaedic department.

(ii) Increase the charges of male patient in ENT department by 3%.

7
(iii) Delete the records of all female patients in Surgery department.

(iv) Display the details of all the patients who are hospitalised in
1998.

(v) SELECT COUNT(DISTINCT Department) FROM HOSPITAL;

8
(vi) SELECT MAX(Age) FROM Hospital WHERE Sex = ‘M’;

(vii) SELECT AVG(Charges) FROM Hospital WHERE SEX = ‘F’;

(viii) SELECT SUM(Charges) FROM Hospital;

9
Table - 4
Q4. Observe the table given below (PharmaDB)
Write command of SQL for (i) to (vi) and output for (vii) to (viii).

(i) To display the names of drugs ending with ‘e’.

(ii) To display all those medicines whose price is in the range 100 to
150.

10
(iii) To display the Maximum price offered by pharmacy located
“Gurgaon”.

(iv) To display the Drug ID, DrugName and Pharmacy Name of all
therecords in descending order of their price.

(v) To display the average price of the drugs.

11
(vi) To display all the pharmacy whose drugs costs less than the
average.

(vii) SELECT RxID, DrugName, Price from PharmaDB where


PharmacyName IN (“Rx Parmacy”, “Raj Medicos”);

(viii) SELECT PharmacyName, COUNT(*) FROM PharmaDB GROUP BY


PharmacyName

12
Table - 5
Q5. Observe the table given below (GYM)
Write command of SQL for (i) to (iv) and output for (v) to (viii).

(i) To display the names of all the items whose name starts with A.

(ii) To display ICODEs and INAMEs of all items, whose Brandname is


Reliable or Coscore.

13
(iii) To change the Brandname to "Fit Trend India" of the item, whose
ICODE as "GIO1".

(iv) Add a new row for a new item in GYM with the details:
"G107","Vibro exerciser",21000,"GTCFitness".

(v) SELECT COUNT(DISTINCT (BRANDNAME)) FROM GYM;

14
(vi) SELECT MAX(PRICE) FROM GYM;

(vii) SELECT INAME FROM GYM WHERE INAME LIKE "*t";

(viii) SELECT ICODE FROM GYM ORDER BY PRICE;

15
Table - 6
Q6.Observe the table given below (DEVICES)
Write command of SQL for (i) to (iv) and output for (v) to (viii).
EmpID Name Device Salary HiringDate
DC242 ABHISHEK HP 80000 2018-03-12
UPMANYU ELITEBOOK
DB922 ANUBHAV BASSI MACBOOK 82000 2017-11-16
PRO
DA042 BISWA KALYAN ASUS 78000 2015-07-21
RATH ZENBOOK
DE916 SAMAY RAINA ACER 79000 2019-07-18
TRITON
DC333 SUMIT SAURAV ROG 75000 2019-08-23
ZEPHYRUS
DF007 TANMAY BHAT HP OMEN 75000 2018-09-20
DB200 ZAKIR KHAN MACBOOK 85000 2015-04-05
AIR

(i) To display Name, EmpID and Device of employees with Salary


more than 79,999.

(ii) To display Name, EmpID, HiringDate and Device of employees


having HP and MACBOOK Devices.

16
(iii) To display Name and Device of employees.

(iv) To add a new row of values (“DD096”, ”ADHIBAN BASKARAN”,


”LENOVO TB”, 77000,2020-08-22).

(v) SELECT Name, Device, EmpID FROM DEVICES WHERE Name


LIKE‘S%’;

17
(vi) SELECT MAX(Salary) FROM DEVICES;

(vii) SELECT EmpID, Name FROM DEVICES


WHERE Salary > 80500
ORDER BY HiringDate;

(viii) SELECT Name FROM DEVICES


WHERE Salary < 79500
ORDER BY HiringDate;

18
Table - 7
Q7.Observe (TABLE.7) the table given below (WORKER)
Write command of SQL for (i) to (iv) and output for (v) to (viii).

i. To create the table worker.

ii. To insert a new tuple with the data (008, Geethika, 74000, 2016-
12-24, ADMIN).

19
iii. To display the details of all the workers of HR department.

iv. To display the name, salary and department of workers in


ascending order w.r.t. joining date.

v. SELECT MAX(Salary) FROM WORKER;

20
vi. SELECT DISTINCT(Department) FROM WORKER;

vii. SELECT Department FROM WORKER WHERE Name LIKE “V%”;

viii. SELECT SUM(Salary) FROM WORKER;

21
Table - 8

Q8. Observe the table given below (GYM)


Write command of SQL for (i) to (vi) and output for (vii) and (viii)

i. To display Mname, Age, FeeGiven of those members whose fee is


above 12,000.

ii. To display Mcode, Mname, Age of all female members of the Gym
with age in descending order.

22
iii. To list names of members and their date of admission of those
members who joined after 31st December, 2015.

iv. To display the Mname, FeeGiven of all those members of the Gym
whose age is less than 40 and are monthly type members of the
Gym.

v. To display names of members who have ‘mit’ anywhere in their


names. For example : Amit, Samit.

23
vi. To display types of memberships available. Duplicate values should
not be displayed.

vii. SELECT SUM(AGE) FROM GYM;

viii. SELECT DISTINCT(Gender) FROM GYM;

24
Table - 9
Q9. Observe the table given below (PEOPLE)
Write command of SQL for (i) to (iv) and output for (v) to (viii):

i. Display the Sur_Name, First_Name and City of people residing in


Udhamwara city.

ii. Display the People IDs (PID), Cities and PinCode of people in
descending order of PinCode.

25
iii. Display the First_Name and City of all the females getting
Basic_salaries above 40000.

iv. Display First_Name and Basic_Salaries of all the persons whose


first name start with ‘G’.

v. SELECT Sur_Name FROM PEOPLE


WHERE Basic_Salary>= 50000;

26
vi. SELECT SUM (Basic_Salary) FROM PEOPLE
WHERE Gender = ‘F’;

vii. SELECT Gender, MIN (Basic_Salary) FROM PEOPLE


GROUP BY Gender;

viii. SELECT Gender, COUNT (*) FROM PEOPLE


GROUP BY Gender;

27
Table - 10
Q10. Observe the table given below (Bank)
Write command of SQL for (i) to (iv) and output for (v) to (viii):

i. To display all the information of account holders whose


transaction value is not mentioned.

ii. To add another column address with datatype VARCHAR and


size(30).

iii. To display all the details in ascending order of date of open

28
iv. To display all the details from table “Bank”, whose date of
open is between ‘2011-01-01’ and ‘2011-12-31’.

v. SELECT Name, Balance FROM Bank WHERE Name LIKE


"%i%";

vi. SELECT ROUND(Balance , -3) FROM Bank WHERE


AccountNo='B2436';

29
vii. SELECT COUNT(DISTINCT Transaction ) FROM Bank ;

viii. SELECT COUNT(*),COUNT(Transaction ) FROM Bank;

**************
30
31

You might also like