0% found this document useful (0 votes)
50 views77 pages

Xii Cs - 2024-25 - Practical File

Uploaded by

shrespoor
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)
50 views77 pages

Xii Cs - 2024-25 - Practical File

Uploaded by

shrespoor
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/ 77

VELAMMAL EDUCATIONAL TRUST

SCHOOL …………………………………………………………………………………………………………

Name: Batch:
Class: Regd No:

Certificate

Certified that this is a bonafide Record of Practical work done by


Mr/Miss …………………………………………………………………
in the …………………..…. Laboratory during the year ………………

Record Total

Teacher - in – charge

Submitted for the Practical Examination in ……………………………………


at ……………………………………………held on……………………………

Principal Internal Examiners External Examiners


CONTENTS
Name: Class:
Teacher
Ex. Date Name of the Experiment Page
’s
No
Initial
Python Program with separate user defined
functions to manipulate strings
1 14-06-2024 1
(i) Seperating URL
(ii) Replacing string
Python Program with separate user defined
functions to manipulate strings
2 21-06-2024 4
(i) Accepting string with all the vowels
(ii) Displaying common string from 2 lines
Python Program with separate user defined
functions to manipulate lists
3 28-06-2024 (i) Displaying indices of non-zero 6
elements
(ii) Double the sum of odd values
Python Program with separate user defined
functions to manipulate lists
4 05-07-2024 8
(i) Storing indices of 4 lettered words
(ii) Swapping adjacent elements
Python Program with separate user defined
functions to manipulate list
5 09-07-2024 10
(i) Find the longest word in the list
(ii) Shifting elements to the left

6 12-07-2024 “Guess the Number” Game using random module 12

Python Program with separate user defined


functions to manipulate tuples
7 16-07-2024 14
(i) Sorting tuples by second item
(ii) Storing student marks in nested tuples

Python program to manipulate customer details in


8 19-07-2024 16
a dictionary

Python program to manipulate text files


9 26-07-2024 (i) Count the occurrences of a word 18
(ii) Count number of vowels & consonants

Python program to manipulate text files


10 02-08-2024 (i) Count the lines start with ‘A’/’B’ 20
(ii) Display the lines with exactly 10 words
CONTENTS
Name: Class:
Teacher’s
Ex. Date Name of the Experiment Page
Initial
No

Python program to manipulate text files


11 09-08-2024 (i) Copying lines to a new file 22
(ii) Replacing the ‘-‘ sign with blankspace

Python program to manipulate text files


12 16-08-2024 (i) Removing duplicate lines 24
(ii) Displaying unique words

Python program to manipulate binary files


(i) Create a file Books.dat and add
13 23-08-2024 28
records
(ii) Search and display the records

Python program to manipulate binary files


(i) Create a file ‘Employees.dat and add
14 30-08-2024 records 32
(ii) Search and update the records
(iii) Display the updated records

Menu Driven Python program to manipulate


binary files
(i) Create a file ‘Products.dat’ and add
15 06-09-2024 36
records
(ii) Search and delete the records
(iii) Display the records

Python program to manipulate csv files


(i) Create a file ‘students.csv’ and add
16 13-09-2024 40
records
(ii) Search and display the records
Menu Driven Python program to manipulate csv
files
(i) Create a file ‘Customers.csv’ and add
17 20-09-2024 42
records
(ii) Search and update the records
(iii) Display the records

18 27-09-2024 Python program to implement a stack using list 48


CONTENTS
Name: Class:
Teacher’s
Ex. Date Name of the Experiment Page
Initial
No

Interfacing Python with MySQL


Database Connectivity Program in Python to
19 04-10-2024 (i) Create a table ‘students’ 52
(ii) Insert records
(iii) Retrieve and display all the records

Interfacing Python with MySQL


Database Connectivity Program in Python to
20 11-11-2024 (i) Create a table ‘students’ 56
(ii) Search and Update the records
(iii) Retrieve and display all the records

Interfacing Python with MySQL


Database Connectivity Program in Python to
(i) Create a table ‘students’
21 18-10-2024 58
(ii) Search and delete records
(iii) Retrieve and display the records
with marks in range 80 to 100

22 25-10-2024 SQL sets

SET 1 60

SET 2 63

SET 3 64

SET 4 65

SET 5 68
Program – 1 - A

Program – 1 - B

1
EX.NO.01 User Defined Functions to Manipulate Strings
Separate URL and Replace String
AIM:

A) To write a function SEP_URL(url) in python to accept an URL of a web page as


argument and return the different parts of it as multiple values.
B) To write a function Replace_Str(S1) in python, that accepts the given text as argument
and replace the word ‘sad’ with ‘happy’ in the first 2 occurrences and replace ‘news’
with ‘information’ only in the first occurrence of the text.
Input Text: I have just received some very sad news. This music always makes me sad. We
all felt sad about his death. The news was devastating to all of us.
SOURCE CODE:
A)

B)

RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the String was successfully completed and executed successfully.

2
Program – 2 - A

Program – 2 - B

3
EX.NO.02 User Defined Functions to Manipulate Strings
Accept String with All Vowels & Display Common words from 2strings
AIM:
A) To write a function VowelStr(data) in python, that accepts a string as argument and to
display “Input Data is accepted” if the string contains all the vowels. If not, display
“Input Data not accepted”.
B) To write a function COMMON(S1,S2) in python to accept 2 strings as arguments and
to find the common words in both the strings.
SOURCE CODE:
A)

B)

RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the String was successfully completed and executed successfully.

4
Program – 3 - A

Program – 3 - B

5
EX.NO: 03 User Defined Functions to manipulate List
Store Indices of Non Zero elements &Double the Odd values
AIM:
A) To write a function INDEX_LIST(L) in python, where L is the list of elements passed
as argument to thefunction. The function returns another list named ‘IndexList’ that stores
the indices of all Non-Zero Elements of L.
For example: If L contains [12,4,0,11,0,56]. The IndexList will have-[0,1,3,5]
B) To write a function DoubletheOdd( ) in python to add and display double the sum of
odd values from the list Nums.
For example : If the Nums contains [25,24,35,20,32,41] .
The function should display Double of Odd Sum: 202
SOURCE CODE:
A)

B)

RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the List was successfully completed and executed successfully.

6
Program – 4 - A

Program – 4 - B

7
EX.NO: 04 User Defined Functions to manipulate List
Store Indices of 4 lettered words &Swap adjacent elements
AIM:
A) To write a function lenFOURword(L) in python , where L is the list of elements
(list of words) passed as an argument to the function. The function returns another list
named ‘indexList’ that stores the indices of all four lettered word of L.
B) To write a function SwapAdjacent(nums) in python, that accepts a list as
argument and interchanges the adjacent elements and prints both the original list and
the modified list.

SOURCE CODE:
A)

B)

RESULT : Thus the python program with user defined functions to perform the
above mentioned tasks in the List was successfully completed and executed
successfully.

8
Program – 5 - A

Program – 5 - B

9
EX.NO:05 User Defined Functions to Manipulate List
Find the Longest Word and Shifting the elements to left

AIM:
A) To write a function Longest_Word(Words_list)in python that accepts a list of words as an
argument and returns the longest word from the list with its length.
B) To write a function Lshift(L,N) in python, where L is the list of elements passed as an
argument to the function. The function shifts all the elements by N places to the left and
then print it.For example: If L contains [9,4,0,3,11,56] and N=2
The function will print - [0,3,11,56,9,4]

SOURCE CODE:

A)

B)

RESULT : Thus the python program with user defined functions to perform the above
mentioned tasks in the List was successfully completed and executed successfully.

10
Program – 6

11
EX.NO:06 “Guess the Number Game” using random module
AIM:
To write a python program to implement
“Guess the NumberGame” using random module.

SOURCE CODE:

RESULT :Thus the python program to implement “Guess the number game” using random
module was executed successfully.

12
Program – 7.1

Program – 7.2

13
EX.NO.07 Sorting List Of Tuples By Second Item &
Manipulate Student Marks In Nested Tuples
AIM:
A) To write a function Sort_Tuple(tup) in python to sort a list of tuples by the second
item.
B) To write a program to create a nested tuple to store student marks and a function
calc(m) to display the total and average of their marks.
SOURCE CODE:
A)

B)
SOURCE CODE:
A)

RESULT: Thus a python program with user defined functions to manipulate the marks
in nested tuples and sort the elements in tuples has been completed and executed
successfully.

14
Program – 8

15
EX.NO.08 Manipulating Dictionary using Functions
AIM: To write a menu driven python program with user defined functions to manipulate
customer details in a dictionary using function.
SOURCE CODE:

RESULT : Thus the menu driven python program with user defined functions to manipulate
the customer details dictionary has been completed and executed successfully.

16
Program – 9
Content of the file TestFile.TXT

Program – 9.1

Program – 9.2

17
EX.NO.09 TEXT FILES IN PYTHON
Count the occurrences of word & Count number of vowels and consonants
AIM:
A) To write a function RainCount() in Python, which should read the content of a text
file ‘TESTFILE.TXT’ and then count and display the count of occurrence of word
RAIN (case-insensitive) in the file.
B) To write a function Vowels() in Python, which should read the content of a text
file ‘TESTFILE.TXT’ and then count and display the number of vowels and
consonants present in the file.
SOURCE CODE:
A)

B)

RESULT : Thus a Python program to read a text file and to count and display the number of
occurrences of a word and number of vowels and consonants in the file has been completed
and executed successfully.

18
Program – 10

Program – 10.1

Program – 10.2

19
EX.NO.10 TEXT FILES IN PYTHON
Count the lines starts with A/B & Display the lines with exactly 6 words
AIM:
A) To write a function Countlines() in Python to read a text file ‘Poem.txt’ and count and
display the number of lines starts with ‘A’ / ‘B’ separately.
B) To write a function ShowLines() in Python, that would read the contents of a text file
‘Poem.txt’ and display only those lines which contains exactly 6 words in it.
SOURCE CODE:
A)

B)

RESULT : Thus a Python program to read a text file and to count the number of lines starts
with A/B and display the lines contain 6 words has been completed and executed
successfully.

20
Program – 11

Program – 11.1

Program – 11.2

21
EX.NO.11 TEXT FILES IN PYTHON
Copying lines to a new file & Replacing the ‘-‘ sign with a blankspace

AIM:

A) Write a function Filter(oldfile,newfile) in Python that would read the contents of the file
‘source.txt’ and copy only those lines which does not contain ‘@’ sign in it to a new text file
‘target.txt’.
B) Write a function Replace() in Python to read the text file ‘Source.txt’ and to replace the ‘-‘ sign
with blankspace in all the occurrences.

SOURCE CODE:

A)

B)

RESULT : Thus a Python program to read a text file and to copy the lines to a new file and
replacing ‘’ sign with a blankspace has been completed and executed successfully.

22
Program – 12 .1

23
EX.NO.12 TEXT FILES IN PYTHON
Remove duplicate lines from the file & Display unique words present in the file
AIM:
A) Write a function RemoveLines() in Python that would read the contents of the file ‘Poem.txt’
and remove the duplicate lines from the file.
B) Write a function UniqueWord() in Python to read the text file ‘Stars.txt’ and to display the
unique words from the file.

SOURCE CODE:

A)

B)

RESULT : Thus a Python program to read a text file and to remove the duplicate lines from
the file and to display the unique words stored in the filehas been completed and executed
successfully.

24
Program – 12.2

25
26
Program – 13

27
EX.NO:13 WORKING WITH BINARY FILE IN PYTHON
Create a binary file, Search and display the records from the binary file
AIM:
(i) To write a user defined function CreateFile() to input the records and add to the binary file
‘Books.dat’ which has the structure [Book_ID, Book_Name, Author, Price].
(ii) To write a function CountRec(Author) which accepts the Author name as parameter and display
the book names and return number of books by the given Author stored in the binary file
‘Books.dat’.
SOURCE CODE:

RESULT:
Thus the user defined functions to create a binary file ‘Books.dat’ and to search and display the book
names number of books by the given Author has been developed in Python and executed
successfully.

28
29
30
Program – 14

31
EX.NO:14 WORKING WITH BINARY FILE IN PYTHON
Create a binary file, Update and display the records from the binary file
AIM:
(i) To write a user defined function AddData() to input and add the records to the binary file
‘Employee.dat’ which has the structure { ‘EmpCode’: , ‘EmpName’: ,
‘Designation’: ,’Salary’: }.
(ii) To write a function UpdateRec(Desgn) which accepts the designation as parameter and update the
salary for the employees with the given designation in the file ‘Employee.dat’. Also display the
records from the file.
SOURCE CODE:

32
33
34
Program – 15

35
36
37
RESULT:
Thus the menu driven python program with separate user defined functions to add records to a binary
file ‘Products.dat’ and to delete and display the records in the file has been developed in Python and
executed successfully.

38
Program - 16

39
EX.NO:16 WORKING WITH CSV FILE IN PYTHON
Create a CSV file, Search and display the records from the CSV file
AIM:
(i) To write a user defined function Create() to input and add the records to the csv file ‘Students.csv’
which has the structure [RollNo, Name, Marks].
(ii) To write a user defined function SearchRec(code) which reads and displays the student records
who have secured above 80 from the file ‘Students.csv’. Also display the number of student records
scored above 80 from the file.
SOURCE CODE:

RESULT:
Thus the user defined functions to add records to a csv file ‘Students.csv’ and to search and display
the records in the file has been developed in Python and executed successfully.

40
Program - 17

41
EX.NO:17 WORKING WITH CSV FILE IN PYTHON
Create a CSV file, Update and display the records from the CSV file

AIM:
To write a Menu driven Python program to implement the following user defined functions.
(i) Create() to input and add the records to the csv file ‘Customers.csv’ which has the structure
[Cust_ID,Cust_Name,City, Contact_No]
(ii) UpdateRec(code) to update the contact number of the customer for the code given by the user
(iii) Display the records stored in the file Customers.csv

SOURCE CODE:

42
43
RESULT:
Thus the menu driven python program with separate user defined functions to add records to a csv file
‘Customers.csv’ and to update and display the records in the file has been developed in Python and
executed successfully.

44
45
46
Program 18

47
EX.NO:18 IMPLEMENTATION OF STACK USING LIST IN PYTHON

AIM:
Consider a dictionary containing non fiction book names and their ratings as key value pairs
as below.
Books={"Behind the beautiful forevers":8.5,"Omnivore's Dilemma":7,"Unnatural
Selection":6.5,"Guns, Germs and Steel":9,"Business Adventures":7.5,"The power of Full
engagement":9.5}
To write a python program with separate user defined functions to perform the following
operations.
(i) Push the keys (Book name) of the dictionary into the stack, where the corresponding value
(rating) is more than 8.
(ii) Pop and display the content of the stack.

Source Code:

48
49
RESULT:
Thus the python program with separate user defined functions to implement the stack using list has
been developed in Python and executed successfully.

50
PROGRAM – 19

51
Ex. No: 19 INTERFACING PYTHON WITH MYSQL
DATABASE CONNECTIVITY APPLICATION PROGRAM - INSERT RECORDS
AIM To write a database connectivity program in Python to establish connection to a MySQL database
‘SCHOOL’ and to do the following.
i) Create a table ‘student’ with the following fields
Rollno-integer(10), primary key, Name varchar(30) not null, Class char(3), Marks decimal(10,2)
ii) To insert the records into the table ‘student’
iii) To retrieve and display all the records stored into the table ‘student’
SOURCE
CODE

RESULT Thus a database connectivity program to create a table, to insert and display the records from the
table student has been created in Python and executed successfully.

52
Program - 19 Cont…

53
54
Program - 20

55
Ex. No: 20 INTERFACING PYTHON WITH MYSQL
DATABASE CONNECTIVITY APPLICATION PROGRAM - UPDATE RECORDS
AIM: To write a database connectivity program in Python to establish connection to a MySQL database
‘SCHOOL’ and to do the following.
i) To update the records into the table ‘student’ for the given rollno
ii) To retrieve and display all the records stored into the table ‘student’
SOURCE
CODE:

RESULT Thus a database connectivity program to update and display the records from the table student has
been created in Python and executed successfully.

56
Program 21

57
Ex. No: 21 INTERFACING PYTHON WITH MYSQL
DATABASE CONNECTIVITY APPLICATION PROGRAM - DELETE RECORDS
AIM: To write a database connectivity program in Python to establish connection to a MySQL database
‘SCHOOL’ and to do the following.
i) To delete the records from the table ‘Student’ for the given rollno
ii) To retrieve and display all the records who have secured marks in the range of 80 to 100 from
the table ‘Student’
SOURCE
CODE:

RESULT Thus a database connectivity program to delete and display the records from the table student has
been created in Python and executed successfully.

58
MySQL Tables
TABLE: OPD

REGNO NAME AGE DEPARTMENT DATEOFREG CHARGES GENDER


R0123 Arpita 62 ENT 2000-01-20 500 M
R0124 Jai 55 Orthopedic 2002-05-22 400 M
R0125 Kamal 34 Gen. Physician 2012-03-14 500 M
R0126 Arun 25 Cardiology NULL 800 M
R0127 Neha 30 ENT 2014-12-16 600 F
R0128 Neetu 28 Cardiology 2015-07-13 500 F
R0129 Ankit 27 Orthopedic NULL 300 F

TABLE: WORKER

WNO WNAME DOJ PAY GENDER DCODE


1001 George K 2013-09-02 75000 MALE D01
1003 Mohitesh 2013-02-03 62000 MALE D05
1002 Anil Jha 2014-01-17 NULL MALE D04
1004 Manila Sahai 2012-12-09 72000 FEMALE D01
1005 R Sahana 2013-11-18 74000 MALE D02
1006 Jaya Priya 2014-06-09 66000 FEMALE D05

TABLE: DEPT

DCODE DEPARTMENT CITY


D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCE MUMBAI

59
EX.NO. 22 SQL
SET - 1

Write the SQL Commands for the following questions based on the table OPD.

1) Insert a record into the table OPD using the following data.
REGNO – R0122, NAME – Jilesha, AGE – 32, DEPARTMENT – Cardiology, CHARGES – 700,
GENDER - F (DATEOFREG is unknown)
INSERT INTO OPD (REGNO, NAME, AGE, DEPARTMENT, CHARGES, GENDER)
VALUES (‘R0122’, ‘Jilesha’, 32, ‘Cardiology’, 700, ‘F’)

2) Add a column EXPERIENCE with datatype integer(10) and NOT NULL constraint.
ALTER TABLE OPD ADD COLUMN EXPERIENCE integer(10) NOT NULL;

3) Display the records of the ENT department from table OPD in alphabetical order as per the name of
the doctors.
SELECT * FROM OPD WHERE DEPARTMENT= ‘ENT’ ORDER BY NAME;

4) Display the Name, Department and charges whose charges are in the range of 500 to 1000.
SELECT NAME, DEPARTMENT, CHARGES FROM OPD
WHERE CHARGES BETWEEN 500 and 1000;

5) Display all the records excluding Gen. Physician Department.


SELECT * FROM OPD WHERE DEPARTMENT < > ‘Gen. Physician’;

SET - 2
Write the SQL Commands for the following questions based on the table OPD.

1) Display REGNO, NAME, DEPARTMENT from the table OPD whose DATEOFREG is not known.
SELECT REGNO, NAME, DEPARTMENT FROM OPD
WHERE DATEOFREG IS NULL;

2) Display the records from the table OPD whose name starts with ‘A’ and contains ‘n’ in it.
SELECT * FROM OPD WHERE NAME LIKE ‘A%n%’;

3) Display the unique values of the DEPARTMENT column of the table OPD.
SELECT DISTINCT DEPARTMENT FROM OPD;

Write the output for the following SQL Commands based on the table OPD.

4) SELECT GENDER, COUNT(*) FROM OPD GROUP BY GENDER;

GENDER COUNT(*)

M 4

F 3

60
TABLE: LAB

LABNO LABNAME INCHARGE CAPACITY FLOOR

L0001 CHEMISTRY Daisy 20 I

L0002 BIOLOGY Venky 20 II

L0003 MATH Preethi 15 I

L0004 LANGUAGE Mary Slim 32 III

L0005 COMPUTER Janani 30 II

TABLE: COMPUTER

PROD_ID PROD_NAME PRICE COMPANY TYPE

P0001 MOUSE 200 LOGITECH INPUT

P0002 LASER PRINTER 4000 CANON OUTPUT

P0003 KEYBOARD 500 LOGITECH INPUT

P0004 JOYSTICK 1000 IBALL INPUT

P0005 SPEAKER 1200 CREATIVE OUTPUT

P0006 DESKJET PRINTER 4300 CANON OUTPUT

TABLE: SALES

PROD_ID QTY_SOLD QUARTER

P0002 4 1

P0003 2 2

P0001 3 2

P0004 5 1

61
5) SELECT DEPARTMENT, MAX(CHARGES) AS ‘Highest Charge’ FROM OPD
HAVING COUNT(*)>1;

DEPARTMENT Highest Charge

ENT 600

ORTHOPAEDIC 400

CARDIOLOGY 800

SET – 3
Write the output for the following SQL Queries based on the relations WORKER and DEPARTMENT.

1) SELECT COUNT(DISTINCT DCODE) FROM WORKER;

COUNT(DISTINCT DCODE)

2) SELECT DCODE, SUM(PAY) AS “TOTAL PAY” FROM WORKER


GROUP BY DCODE HAVING COUNT(*) > 1;

DCODE TOTAL PAY

D01 147000

D05 128000

3) SELECT WNAME, DEPARTMENT, CITY FROM WORKER W, DEPARTMENT D


WHERE W.DCODE = D.DCODE AND WNO>1003;

WNAME DEPARTMENT CITY

Manila Sahai MEDIA DELHI

R Sahana MARKETING DELHI

Jaya Priya FINANCE KOLKATA

62
TABLE: PRODUCT

P_ID PNAME MANUFACTURER PRICE DISCOUNT

TP01 Talcum Powder LAK 40 NULL

FW05 Face Wash ABC 45 5

BS14 Bath Soap SEN 55 10

SH06 Shampoo XYZ 120 NULL

FW12 Face Wash XYZ 95 12

SH10 Talcum Powder ABC 70 NULL

TABLE: CLIENT

C_ID CNAME CITY P_ID

01 Cosmetic Shop Delhi TP01

02 Total Health Mumbai FW05

03 Live Life Delhi BS01

04 Pretty Woman Mumbai SH06

05 Dreams Bengaluru FW12

63
4) SELECT WNO, WNAME, DEPARTMENT FROM WORKER W
RIGHT JOIN DEPARTMENT D ON W.DCODE = D.DCODE;

WNO WNAME DEPARTMENT

1001 George K MEDIA

1004 Manila Sahai MEDIA

1005 R Sahana MARKETING

NULL NULL INFRASTRUCTURE

1003 Mohitesh FINANCE

1006 Jaya Priya FINANCE

1002 Anil Jha HUMAN RESOURCE

5) SELECT MIN(PAY) FROM WORKER WHERE DOJ>’2013-01-01’;

MIN(PAY)

62000

6) SELECT GENDER, AVG(PAY) AS “AVERAGE PAY” FROM WORKER


GROUP BY GENDER;

GENDER AVERAGE PAY

MALE 70333.33

FEMALE 69000.00

SET - 4
Write the SQL commands for the following based on the table LAB.

1) Increase the capacity of all the labs by 10 students which are on the I floor.
UPDATE LAB SET CAPACITY = CAPACITY + 10
WHERE FLOOR = ‘I’;

2) Remove the LANGUAGE LAB record from the table LAB.


DELETE FROM LAB WHERE LABNAME=’LANGUAGE’;

3) Add Primary key constraint to the column LABNO.


ALTER TABLE LAB ADD PRIMARY KEY(LABNO);

64
65
Write the outputs of the SQL Queries 4 to 7 based on the relations COMPUTER and SALES.

4) SELECT MIN(PRICE), MAX(PRICE) FROM COMPUTER;

MIN(PRICE) MAX(PRICE)

200 4300

5) SELECT COMPANY, SUM(PRICE) FROM COMPUTER


GROUP BY COMPANY HAVING COUNT(COMPANY)>1;

COMPANY SUM(PRICE)

LOGITECH 700

CANON 8300

6) SELECT PROD_NAME, QTY_SOLD FROM COMPUTER C.SALES S


WHEREC.PROD_ID = S.PROD_ID AND TYPE= ‘INPUT’;

PROD_NAME QTY_SOLD

MOUSE 3

KEYBOARD 2

JOYSTICK 5

7) SELECT * FROM COMPUTER NATURAL JOIN SALES;

PROD_ID PROD_NAME PRICE COMPANY TYPE QTY_SOLD QUARTER

P0001 MOUSE 200 LOGITECH INPUT 3 2

P0002 LASER 4000 CANON OUTPUT 4 1


PRINTER

P0003 KEYBOARD 500 LOGITECH INPUT 2 2

P0004 JOYSTICK 1000 IBALL INPUT 5 1

66
67
SET - 5
Write the SQL commands for the following questions based on the tables PRODUCT and CLIENT.

1) To display details of products whose manufacturer is either ABC or XYZ.


SELECT * FROM PRODUCT
WHERE MANUFACTURER IN (‘ABC’, ‘XYZ’);

2) To display Product name, manufacturer and price for all the products that are giving discount.
SELECT PNAME, MANUFACTURER, PRICE FROM PRODUCT
WHERE DISCOUNT IS NOT NULL;

3) To display Product name and price for all the products whose name does not end with ‘Wash’.
SELECT PNAME, PRICE FROM PRODUCT
WHERE PNAME NOT LIKE ‘%Wash’;

4) To display the P_ID, Product name and Client name for all the clients whose city is Delhi.
SELECT P. P_ID, PNAME, CNAME FROM PRODUCT P, CLIENT C
WHERE P. P_ID = C. P_ID and C. CITY = ‘Delhi’;

Write the output for the following SQL Queries based on the tables given PRODUCT and CLIENT.

5) SELECT P_ID, PNAME, CNAME, CITY FROM PRODUCT P LEFT JOIN CLIENT C
ON P. P_ID = C. P_ID ;

P_ID PNAME CNAME CITY

TP01 Talcum Powder Cosmetic Shop Delhi

FW05 Face Wash Total Health Mumbai

BS14 Bath Soap NULL NULL

SH06 Shampoo Pretty Woman Mumbai

FW12 Face Wash Dreams Bengaluru

SH10 Talcum Powder NULL NULL

6) SELECT PNAME, COUNT(*) FROM PRODUCT GROUP BY PNAME ORDER BY PNAME;

PNAME COUNT(*)

Bath Soap 1

Face Wash 2

Shampoo 1

Talcum Powder 2

68
69
7) SELECT PNAME, MIN(PRICE) AS “LOWEST PRICE” FROM PRODUCT
GROUP BY PNAME HAVING COUNT(*)>1;

PNAME LOWEST PRICE

Talcum Powder 40

Face Wash 45

8) SELECT DISTINCT CITY FROM CLIENT;

CITY

Delhi

Mumbai

Bengaluru

9) SELECT COUNT(DISCOUNT) FROM PRODUCT;

COUNT(DISCOUNT)

10) SELECT P_ID, PNAME, CNAME, CITY FROM PRODUCT P RIGHT JOIN CLIENT C
ON P. P_ID = C. P_ID ;

P_ID PNAME CNAME CITY

TP01 Talcum Powder Cosmetic Shop Delhi

FW05 Face Wash Total Health Mumbai

NULL NULL Live Life Delhi

SH06 Shampoo Pretty Woman Mumbai

FW12 Face Wash Dreams Bengaluru

70

You might also like