Practical 12
Practical 12
Entry of each program / SQL Statements should be made in Index with page number
and experiment date.
Type of Practical Notebook should be ‘Computer Practical Notebook’.
All the solution to be written in a single NoteBook.
SQL Statements
Consider the following Table structures:
Page 1 of 6
Page 2 of 6
Problem 1: Date:(09-04-2024)
Write SQL Statements for the following problems:
1. Display the CustomerName, InvoiceNo, SaleDate and Saleprice for the car sold.
2. Display list of Employee with InvoiceNo and SalePrice.
Problem 2: Date:(12-04-2024)
1. Display the CustomerName, InvoiceNo, SaleDate and Saleprice for the car sold who have made online
payment.
2. Display Details of Customers who have purchased the car. The details should contain – Customer name,
Phone, CarName, Model, Price, FuelType and date of purchage.
Problem 3: Date:(18-04-2024)
1. Display total amount of sale done by the company.
2. Display name of customer with number of car purchased by him/her.
3. Display name of customers who have purchased petrol car.
Problem 4: Date:(25-04-2024)
1. Display last four letters of each Employee name.
2. Display 5 letters of customer name starting from 4th letter.
3. Display first 5 letters in uppercase from customer name.
4. Display name and only emailed (not domain name) of customers.
Problem 5: Date:(29-04-2024)
Write the output produced by the following SQL commands:
a. SELECT POW(2,3);
b. SELECT ROUND(123.2345, 2), ROUND(342.9234,-1);
c. SELECT LENGTH("Informatics Practices");
d. SELECT YEAR(“1979/11/26”), MONTH(“1979/11/26”), DAY(“1979/11/26”), MONTHNAME(“1979/11/26”);
e. SELECT LEFT("INDIA",3), RIGHT("Computer Science",4);
f. SELECT MID("Informatics",3,4), SUBSTR("Practices",3);
Problem 6: Date:(02-05-2024)
Consider the following table named “Product”, showing details of products being sold in a grocery shop.
Write SQL queries for the following:
a. Create the table Product with appropriate data types and constraints.
b. Identify the primary key in Product.
c. List the Product Code, Product name and price in descending order of their product name. If PName is the
same then display the data in ascending order of price.
d. Add a new column Discount to the table Product.
e. Calculate the value of the discount in the table Product as 10 per cent of the UPrice for all those products
where the UPrice is more than 100, otherwise the discount will be 0.
f. Increase the price by 12 per cent for all the products manufactured by Dove.
g. Display the total number of products manufactured by each manufacturer.
Page 3 of 6
Problem 7: Date:(06-05-2024)
Write the output(s) produced by executing the following queries on the basis of the information given above
(Problem 6) in the table Product:
a. SELECT PName, Average(UPrice) FROM Product GROUP BY Pname;
b. SELECT DISTINCT Manufacturer FROM Product;
c. SELECT COUNT(DISTINCT PName) FROM Product;
d. SELECT PName, MAX(UPrice), MIN(UPrice) FROM Product GROUP BY PName;
Problem 8: Date:(09-05-2024)
Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following:
a. Add a new column Discount in the INVENTORY table.
b. Set appropriate discount values for all cars keeping in mind the following:
(i) No discount is available on the LXI model.
(ii) VXI model gives a 10% discount.
(iii) A 12% discount is given on cars other than LXI model and VXI model.
c. Display the name of the costliest car with fuel type “Petrol”.
d. Calculate the average discount and total discount available on Car4.
e. List the total number of cars having no discount.
Problem 9: Date:(13-05-2024)
Consider the following tables Student and Stream in the Streams_of_Students database. The primary key of
the Stream table is StCode (stream code) which is the foreign key in the Student table. The primary key of the
Student table is admNo (admission number).
Write SQL queries for the following:
a. Create the database Streams_Of_Students.
b. Create the table Student by choosing appropriate data types based on the data given in the table.
c. Identify the Primary keys from tables Student and Stream. Also, identify the foreign key from the table
Stream.
d. Jay has now changed his stream to Humanities. Write an appropriate SQL query to reflect this change.
e. Display the names of students whose names end with the character ‘a’. Also, arrange the students in
alphabetical order.
f. Display the names of students enrolled in Science and Humanities stream, ordered by student name in
alphabetical order, then by admission number in ascending order (for duplicating names).
g. List the number of students in each stream having more than 1 student.
h. Display the names of students enrolled in different streams, where students are arranged in descending
order of admission number.
i. Show the Cartesian product on the Student and Stream table. Also mention the degree and cardinality
produced after applying the Cartesian product.
j. Add a new column ‘TeacherIncharge’ in the Stream table. Insert appropriate data in each row.
k. List the names of teachers and students.
l. If Cartesian product is again applied on Student and Stream tables, what will be the degree and cardinality of
this modified table?
Page 4 of 6
Python Programs
Write python program for the following:
1. To display reverse of a given number.
2. To display the sum of digits of a given number.
3. Create array of 10 numbers and display them one by one.
4. Create a series and display its element using for loop.
5. To create two series and display the series after using addition.
6. Create the following Series and do the specified operations:
a) EngAlph, having 26 elements with the alphabets as values and default index values.
b) Vowels, having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ and all the five values set to zero.
Check if it is an empty series.
c) Friends, from a dictionary having roll numbers of five of your friends as data and their first name as
keys.
d) MTseries, an empty Series. Check if it is an empty series.
e) MonthDays, from a numpy array having the number of days in the 12 months of a year. The labels
should be the month numbers from 1 to 12.
7. Using the Series created in Question 6, write commands for the following:
a) Set all the values of Vowels to 10 and display the Series.
b) Divide all values of Vowels by 2 and display the Series.
c) Create another series Vowels1 having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ having values
[2,5,6,3,8] respectively.
d) Add Vowels and Vowels1 and assign the result to Vowels3.
e) Subtract, Multiply and Divide Vowels by Vowels1.
f) Alter the labels of Vowels1 to [‘A’, ‘E’, ‘I’, ‘O’, ‘U’].
8. Using the Series created in Question 5, write commands for the following:
a) Find the dimensions, size and values of the Series EngAlph, Vowels, Friends, MTseries, MonthDays.
b) Rename the Series MTseries as SeriesEmpty.
c) Name the index of the Series MonthDays as monthno and that of Series Friends as Fname.
d) Display the 3rd and 2nd value of the Series Notes Friends, in that order.
e) Display the alphabets ‘e’ to ‘p’ from the Series EngAlph.
f) Display the first 10 values in the Series EngAlph.
g) Display the last 10 values in the Series EngAlph.
h) Display the MTseries.
9. Using the Series created in Question 5, write commands for the following:
a) Display the names of the months 3 through 7 from the Series MonthDays.
b) Display the Series MonthDays in reverse order.
Create the following DataFrame Sales containing year wise sales figures for five sales persons in INR. Use
the years as column labels, and sales person names as row labels.
10. Create the following DataFrame Sales containing year wise sales figures for five sales persons in INR. Use
the years as column labels, and sales person names as row labels.
12. Write the python statement for the following question on the basis of given dataset:
Page 6 of 6