0% found this document useful (0 votes)
16 views2 pages

SET (A) Solution

The document contains instructions to create MySQL tables, insert sample data, and perform queries on the tables: 1. It creates Personal and Job tables with relevant columns, and inserts sample records. 2. It queries the tables to retrieve empno, name, and salary of employees with hobby as 'Sports', ordered by name. 3. It queries to retrieve name and dept of employees retiring in March 2027. 4. It updates the salary of employees whose app_date is after 31st December 2006 by increasing it by 500.

Uploaded by

Ariyan Kushvaha
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)
16 views2 pages

SET (A) Solution

The document contains instructions to create MySQL tables, insert sample data, and perform queries on the tables: 1. It creates Personal and Job tables with relevant columns, and inserts sample records. 2. It queries the tables to retrieve empno, name, and salary of employees with hobby as 'Sports', ordered by name. 3. It queries to retrieve name and dept of employees retiring in March 2027. 4. It updates the salary of employees whose app_date is after 31st December 2006 by increasing it by 500.

Uploaded by

Ariyan Kushvaha
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/ 2

1. Read a text file ‘data.

txt’ and display the number of spaces, digits, uppercase letters and
lowercase letters present in file.

# this will open the file and store in


# "file" variable
file = open("test1.txt", "r")
count = 0
while True:
# this will read each character
# and store in char
char = file.read(1)
if char == " ":
count += 1
if not char:
break
print(count)
f = open("content.txt","r")
text = f.read()
count_digit = 0
for char in text:
if char.isdigit():
count_digit += 1
print(count_digit)
f.close()
myfile = open("Answer.txt", "r")
lcount = 0
ucount = 0
file_data=myfile.read()
for i in file_data:
if i.isupper() == True:
ucount = ucount + 1
elif i.islower() == True:
lcount = lcount + 1
else:
None
print("Uppercase letters in the file :", ucount)
print("Lowercase letters in the file :", lcount)
myfile.close()
2. Consider following tables Personal and Job and solve the queries given below:
i. Create above tables Personal and Job in MySQL and insert records in both the tables.
ii. Show empno, name and salary of those who have Sports as hobby in ascending order of name.
iii. Show Name and Dept of employees who are going to retire in month of March and in year 2027.
iv. Increase salary by 500 of those employees whose App_date is after 31st December 2006.

(1) mysql> CREATE TABLE Personal (Empno integer NOT NULL UNIQUE, name VARCHAR(20), dobirth
DATE, Native VARCHAR (20), hobby VARCHAR(20));
INSERT INTO Personal VALUES(123,'Amit',’1965-01-23’,’Delhi’, ‘Music’);
INSERT INTO Personal VALUES(127, Manoj,’1976-12-12’, Mumbai, ‘Writing);
INSERT INTO Personal VALUES(124, Abhai, ‘1976-12-12’, Allahabad, ‘Music’);
INSERT INTO Personal VALUES(125, Vinod, ‘1977-04-04’,’Delhi’, ‘Sports);
INSERT INTO Personal VALUES(128, Abhay, ‘1974-03-10’, Mumbai,
‘Gardening);
INSERT INTO Personal VALUES(129, Ramesh, 1981-10-28, Pune, ‘Sports);
mysql> CREATE TABLE Job (Sno VARCHAR(10), Area VARCHAR(20), App_date DATE, Salary integer,
Retd_date DATE, Dept VARCHAR(20));
INSERT INTO Job VALUES(123,'Agra',’2006-01-25’,5000,’2026-01-
25’,’Marketing’);
INSERT INTO Job VALUES(127,' Mathura',’2006-12-25’,16000,’2026-12-22’,’
Finance’);
INSERT INTO Job VALUES(124,'Agra',’2007-08-19’,10500,’2027-03-
19’,’Marketing’);
INSERT INTO Job VALUES(125,' Delhi',’2004-04-14’,8500,’2028-04-
14’,’Sales’);
INSERT INTO Job VALUES(128,' Pune',’2008-03-13’,7500,’2028-03-
13’,’Sales’);
(2) Select Personal .Empno , Personal .name , Job.salary from Personal inner join Personal .Empno on
Job.Sno where and Personal.Hobby = “Sports” order by name asc;
(3) Select Personal .Name and Job .Dept from personal inner join Personal .Empno on Job.Sno where
Retd_date is between ‘2027-03-01’ and ‘2027-03-31 ‘;
(4) Update Job

set salary = salary + 500


where App_date > ‘31-12-2006’ ;

You might also like