SQL Exercise
SQL Exercise
SQL EXERCISE 1
Output:
1. SELECT * FROM CLIENT WHERE CITY =’DELHI’;
C_ID CLIENTNAME CITY P_ID
01 COSMETIC SHOP DELHI FW05
12 LIVE LIFE DELHI SHO6
15 PRETTY WOMAN DELHI FW12
3. SELECT CLIENTNAME, CITY, PRICE FROM CLIENT , PRODUCT WHERE CLIENT.P_ID =PRODUCT.P_ID;
TABLE : CONSIGNEE
CNEEID CNORID CNEENAME ADDRESS CNEECITY
MU05 ND01 RAHUL KISHORE 5, PARK AVENUE MUMABI
ND08 ND02 P.DHINGRA 16/5, MOORE EOC NEW DELHI
K019 MU15 A P ROY 2/A CENTRAL AV KOLKATA
MU32 NDO2 S.MITTAL 0-245, ABCD MUMBAI
ND48 MU05 B.P.MITTAK 13, BLOCK D AV NEW DELHI
Output:
1. SELECT CNORNAME FROM CONSIGNOR WHERE CITY =’MUMBAI’;
CNORNAME
R KOHLI
S KAUR
CNEECITY COUNT(CNEECITY)
MUMABI 2
NEW DELHI 2
KOLKATA 1
SQL EXERCISE 3:
TABLE :STOCK
Itemno Item Dcode Qty Unitprice Stockdate
5005 Ball Pen 0.5 102 100 16 2010-03-31,
5003 Ball pen 0.25 102 150 20 2020-01-01
5002 Gel Pen Premium 101 125 14 2010-02-14
5006 Gel Pen classic 101 200 22 2009-01-01
5001 Eraser Small 102 210 5 2009-03-19
5004 Eraser Big 102 60 10 2009-12-12
5009 Sharpener Classic 103 160 8 2009-01-23
Table: Dealers
Dcode Dname
101 Reliable Stationers
103 Classic Plastics
102 Clear Deals
Output:
1.SELECT * FROM Stock ORDER BY Stockdate;
Itemno Item Dcode Qty Unitprice Stockdate
5006 Gel Pen classic 101 200 22 2009-01-01
5009 Sharpener Classic 103 160 8 2009-01-23
5001 Eraser Small 102 210 5 2009-03-19
5004 Eraser Big 102 60 10 2009-12-12
5003 Ball pen 0.25 102 150 20 2010-01-01
5002 Gel Pen Premium 101 125 14 2020-02-14
5005 Ball Pen 0.5 102 100 16 2010-03-31
SQL EXERCISE 4:
TABLE :Employees
Empid Firstname Lastname Address City
010 Ravi Kumar Raj nagar GZB
105 Harry Waltor Gandhi nagar GZB
152 Sam Tones 33 elm st. Paris
215 Sarah Ackerman 440 u.s. 10 Upton
244 Manila Senupta 24 friends street New delhi
300 Robert Samuel 9 fifth cross Washington
335 Ritu Tondon Shastri nagar GZB
400 Rachel Lee 121 harrison st. New yark
441 Peter Thompson 11 red road Paris
TABLE : EmpSalary
Empid Salary Benefits Designation
3. SELECT Firstname, Lastname, Salary+Benefits as ‘Total Salary’ FROM Employees, Empsalary where
Employees.Empid=Empsalary.Empid and Designation=’Manager’;
Firstname Lastname Salary Benefits Total Salary
Ravi Kumar 75000 15000 90000
Harry Waltor 65000 15000 80000
Sarah Ackerman 75000 12500 87500
4. SELECT Desgination, MAX(Salary) FROM Empsalary GROUP by Designation;
Designation MAX(Salary)
Manager 75000
Director 80000
Clerk 50000
Salesman 32000
SQL EXERCISE 5:
Table : Books
Book_id Book_name Author_name Publishers Price Type Qty
C0001 Fast cook Lata kapoor EPB 355 Cookery 5
F0001 The tears William First publ. 650 Fiction 20
hopkins
T0001 My frist c++ Brain & EPB 350 Text 10
brooke
T0002 C++ brainworks A w rossaine TDH 350 Text 15
F0002 Thunderbolts Anna roberts First publ. 750 Fiction 50
TABLE : Issued
Book_id Quantity_issued
T0001 4
C0001 5
F0001 2
Output:
1. SELECT Book_name, Author_name, Price FROM Books WHERE Publishers=’Firt Publ.’;
Book_name Author_name
The tears William hopkins
Thunderbolts Anna roberts
The values of fields rno, name, DOB and fee has to be accepted from the user. Help
Kabir to write the program in Python.
2. Raj wants to write a program in Python to deletes the records with Ecode as
“E101” or “ E105” from the table named employee in MYSQL database,
EMP:
Ecode - String
Ename - string
Sal- Integer
City – String
3. Hemanth wants to write a program in Python to read the following records from
the table employee and displays only those records who have employees coming
from city “Delhi”.
Ecode - String
Ename - string
Sal- Integer
City – String
4. Srilakshmi wants to write a program in Python to increase the marks by 5 for all 12
std students in the table Midterm.
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and
MYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named school.