Friday, 7 November 2025

Sample practical paper II

 SECTION A


1. Write a menu driven program to operate on a csv file courier.csv with each record as a list of the

form :

[courier_id, name, city, fees].

The menu should

a) Insert records into the file.

b) Display records, the total of the fees and the average fees

c) Search and display the details of a given courier_id

2. Your Principal has chosen you to to help maintain the records of grade 12 students in a stack format.

Each record should contain { ‘s_id’:int, ‘s_name’:str , ‘s_marks’: int}

You decide to implement stack data structure to maintain the records of your classmates to perform the

following operations on the stack , in a menu driven fashion

i) Push

ii) Pop

iii) Display (at the end of the display , print the average marks of the students, and the topper’s details)


SECTION B


3.Consider the following table:

Write SQL Queries to create the above tables and insert records into them, and write queries for

the following:

a) To display employee ids, names of employees, job ids with corresponding job titles. 

b) To display names of employees, sales and job titles who have achieved sales more than 1300000.

c) To display names who have ‘SINGH’ (anywhere) in their names.

d) Write SQL command to change the jobid to 104 of the employee with ID as E4 in the table

Employee.

e) Display a list of jobid, job name and number of employees

f) Display only the jobs with salary greater than or equal to the average salary.

g) Increase “manager” salary by 5 percent.

Sample practical paper - I

 SECTION A


1. Write a menu-driven program to operate on a binary file book.dat with each record stored as a list in

the form:

[book_id (int), book_title (string), price (int)].

The menu should perform the following operations:

a) Insert records into the file.

b) Display all records, the total cost of all books, and the average price of books.

c) Update the price of a given book_id, else display a suitable message.


2. You are an excellent coder. So your neighbour Amit, who owns a departmental store tells you to help

him maintain the records of a customer’s cart in a stack format.

You decide to implement stack data structure to maintain the records of the shopping cart to perform the

following operations on the stack the, in a menu driven fashion

i) Push

ii) Pop

iii) Display (at the end of the display , print the total price of the cart)

Note : Each record is of the structure :

{‘p_id’: int , ‘p_name’ :str , ‘price’: float}.


SECTION B


3. Create the below tables and write the SQL statements for the queries that follow :


1. Display the names of borrowers who borrowed a book in December 2024.

2. List the book titles borrowed by borrowers living in Mumbai.

3. Find the total number of books borrowed by each borrower( id and name).

4. Display the city-wise count of books borrowed in descending order of count.

5. List the names of borrowers who have not returned at least one book

6. Display the borrowers who have returned all the books .

7. Update return date of Kavya Iyer’s unreturned books to 2025-09-09.


Thursday, 6 November 2025

Binary files practice

 Write a Python functions :

STUDENT_ADD() that adds new students to the file student.dat. 

Each record in the file contains the following information for a student:

  • Roll Number (integer)

  • Name (string)

  • sPercentage (float)

STUDENT_UPDATE() that changes the percentage of a certain roll number.

>Display if student not found



Monday, 3 November 2025

CSV file practice


(a) Write one point of difference between seek() and tell() functions in file handling. Write a program in Python that defines and calls the following user defined functions :

(i) Add_Device() : The function accepts and adds records of the peripheral devices to a csv file ‘peripheral.csv’. Each record consists of a list with field elements as P_id, P_name and Price to store peripheral device ID, device name, and price respectively.

(ii) Count_Device() : To count and display number of peripheral devices, whose price is less than ₹1000.

                                                   

(b) Write a program in Python that defines and calls the following user defined functions :

(i) Add_Teacher() : It accepts the values from the user and inserts record of a teacher to a csv file “Teacher.csv”. Each record consists of a list with field elements as T_id, Tname and desig to store teacher ID, teacher name and designation respectively.

(ii) Search_Teacher() : To display the records of all the PGT (designation) teachers.


Sunday, 2 November 2025

Text file practice

''' Write a function in Python that copies the book names having ‘Y’ or ‘y’ in

their name from a text file

“Bookname.txt” into another file Yy.txt Finally display Yy.txt and the total

number of Books in the text..

Example:

If the file ‘Bookname.txt’ contains the names of following books :

One Hundred Years of Solitude

The Diary of a Young Girl

On the Road

After execution, the output will be :

One Hundred Years of Solitude

The Diary of a Young Girl

No of Books in Yy.txt : 2'''


def func():

    l=[]

    with open('bookname.txt','r') as f:

        text=f.read()

        lines=text.splitlines()

        for i in lines:

            if 'y' in i or 'Y' in i:

                l.append(i)


    with open('yy.txt','w') as f:

        f.writelines(l)


    with open('yy.txt','r') as f:

        text=f.read()

        lines=text.splitlines()

        print(text)

        print('no of books : ',len(lines))



'''

Write a function RevString() to read a textfile “Input.txt” and prints the words starting with

‘O’ in reverse order. The rest of the content is displayed normally.


Example:

If content in the text file is :

UBUNTU IS AN OPEN SOURCE OPERATING SYSTEM



Output will be :

UBUNTU IS AN NEPO SOURCE GNITAREPO SYSTEM

(words ‘OPEN’ and ‘OPERATING’ are displayed in reverse order)

'''       

with open('input.txt','r') as f:

        text=f.read()

        s=''

        words=text.split()

        for i in words:

            if i[0].lower()=='o':

                s=s+i[::-]+' ')

            else:

                s=s+i

print(s)


Monday, 27 October 2025

Dictionaries practice

 

  1. Write a menu-driven program to create a dictionary called HOTEL and provide the following functions:

    a) ADD n rooms to the dictionary HOTEL, where each room description is stored as

    {ROOM_NO : [GUEST_NAME, ROOM_TYPE, NO_OF_DAYS, BILL]}
    • Ensure the ROOM_TYPE => Standard(default), Deluxe, Supreme or Suite

    • BILL → calculated based on room type and number of days

    • Room TypeCost per Day (₹)
      Standard1500
      Deluxe2500
      Supreme3500
      Suite5000

    b) SEARCH for a room using its ROOM_N and increase the stay by 1 day.
    The BILL should be recalculated accordingly. Display ROOM NOT FOUND in case not found

    c) DISPLAY all room records in a tabular form showing:

    Room No | Guest Name | Room Type | Days | Bill
  • Also display the total bill amount collected. 

Wednesday, 15 October 2025

GRADE 12 : PRACTICAL 21

 '''WAP using Python-MySQL connectivity to connect to the given DB and perform the queries for the following :

> UPDATE NO. OF PARTICIPANTS AFTER ACCEPTING THE ACTIVITY NAME

> FINALLY DISPLAY ALL THE DATA AND THE TOTAL NUMBER OF ROWS

TABLE : ACTIVITY

 ACODE| ANAME         | STADIUM     | NO | PRIZE | SCHEDULE_DATE  

-----------------------------------------------------------------------

1001  | RELAY 100M    | STAR ANNEX  | 16 | 10000 | 2004-01-23

1002  | HIGH JUMP     | STAR ANNEX  | 10 | 12000 | 2003-12-12

1003  | SHOTPUT       | SUPER POWER | 12 | 8000  | 2004-02-14

1005  | LONG JUMP     | STAR ANNEX  | 12 | 9000  | 2004-01-01

1008  | DISCUS THROW  | SUPER POWER | 10 | 15000 | 2004-03-19

---------------------------------------------------------------------- '''



Do not write this part : 
create table activity(
acode int primary key,
aname varchar(50),
stadium varchar(50),
no int,
prize int,
scheduled_date date);


insert into activity values
(1001,'RELAY 100M','STAR ANNEX',16,10000,'2004-01-23'),
(1002,'HIGH JUMP','STAR ANNEX',10,12000,'2003-12-12'),
(1003,'SHOTPUT','SUPER POWER',12,8000,'2004-02-14'),
(1005,'LONG JUMP','STAR ANNEX',12,9000,'2004-01-01'),
(1008,'DISCUS THROW','SUPER POWER',10,15000,'2004-03-19');


import mysql.connector as my

conn = my.MySQLConnection(host='localhost', user='root', password='123456789', database='lab21')
if conn.is_connected():
        print('Connected to MySQL successfully!')
else:
        print('Connection is unsuccessful!')
cur = conn.cursor(buffered=True)
print()

#UPDATE NO. OF PARTICIPANTS AFTER ACCEPTING THE ACTIVITY NAME
print('TO UPDATE NO. OF PARTICIPANTS AFTER ACCEPTING THE ACTIVITY NAME:')
aname=input('Enter name of Activity to be updated:')
cur.execute('select * from activity where aname=%s',(aname,))
rec=cur.fetchall()
if rec:
    print('Record found:',rec)
    no=int(input('Enter new participant count:'))
    cur.execute('update activity set no=%s where aname=%s',(no,aname))
    print('Data updated successfully!')
else:
    print('No such record found!')
conn.commit()
cur.reset()
print()

#DISPLAY ALL THE DATA AND THE TOTAL NUMBER OF ROWS
print('DISPLAY ALL THE DATA AND THE TOTAL NUMBER OF ROWS:')
cur.execute('select * from activity')
recs=cur.fetchall()
if recs:
    for a,b,c,d,e,f in recs:
        print(a,b,c,d,e,f, sep='| ')
else:
    print('Table empty! No records exist.')

count=cur.rowcount
print('Row count:', count)

cur.close()
conn.close()

GRADE 12 : PRACTICAL 20

 WAP using Python-MySQL connectivity to connect to the given table and perform the following :

DISPLAY DESIRED NUMBER OF RECORDS UPDATE THE TRAINS HAVING START AS 'PUNE JUNCTION' TO 'MUMBAI' . DELETE DATA WHOSE END IS 'HABIBGANJ' FINALLY DISPLAY ALL THE ROWS & THE NO. OF ROWS

TABLE : TRAIN ,     DATABASE : PRACT20

 TNO  | TNAME                | START              | END 

-----------------------------------------------------------------------

11096 | AHIMSA EXPRESS       | PUNE JUNCTION      | AHMEDABAD JUNCTION

12015 | AJMER SHATABDI       | NEW DELHI          | AJMER JUNCTION

16513 | PUNE HBJ SPECIAL     | PUNE JUNCTION      | HABIBGANJ

13005 | AMRITSAR MAIL        | HOWRAH JUNCTION    | AMRITSAR JUNCTION  

12002 | BHOPAL SHATABDI      | NEW DELHI          | HABIBGANJ

---------------------------------------------------------------------- '''


THIS PART IS NOT TO BE WRITTEN IN RECORD

CREATE DATABASE PRACT20; USE PRACT20; CREATE TABLE TRAIN ( TNO INT PRIMARY KEY, TNAME VARCHAR(50), START VARCHAR(50), END VARCHAR(50) );

INSERT INTO TRAIN VALUES (11096, 'AHIMSA EXPRESS', 'PUNE JUNCTION', 'AHMEDABAD JUNCTION'), (12015, 'AJMER SHATABDI', 'NEW DELHI', 'AJMER JUNCTION'), (16513, 'PUNE HBJ SPECIAL', 'PUNE JUNCTION', 'HABIBGANJ'), (13005, 'AMRITSAR MAIL', 'HOWRAH JUNCTION', 'AMRITSAR JUNCTION'), (12002, 'BHOPAL SHATABDI', 'NEW DELHI', 'HABIBGANJ');


WRITE IT IN THE RECORD

import mysql.connector as my
import sys con=my.connect(host='localhost', user='root', password='1234', database='lab20', use_pure=True) #use_pure when set to True ensures that the connection is made purely using python if con.is_connected(): print('Connected To MySQL Server Successfully') else: sys.exit('Connection To MySQL Server Failed!') cur=con.cursor()
print('''DISPLAY DESIRED NUMBER OF RECORDS''') cur.execute("select * from train") n=int(input('Enter the number of records to fetch: ')) recs=cur.fetchmany(n) # fetches 'n' records for no,name,start,end in recs: print(no,name,start,end, sep=' | ') print() cur.reset() print("""UPDATE THE TRAINS HAVING START AS 'PUNE JUNCTION' TO 'MUMBAI'""")
cur.execute("select * from train where start='PUNE JUNCTION'")
rec=cur.fetchone() if not rec:
    print('No such record found' )
else:
    cur.execute("update train set start = 'MUMBAI' where start = 'PUNE JUNCTION'")     con.commit() print("""DELETE DATA WHOSE END IS 'HABIBGANJ'""")
cur.execute("select * from train where end='HABIBGANJ'")
rec=cur.fetchone() if not rec:
    print('No such record found' )
else:
    cur.execute("delete from train where end='HABIBGANJ'")     con.commit() print('''DISPLAY ALL THE ROWS & THE NO. OF ROWS''') print('TNO', 'TNAME', 'START', 'END',sep=' | ') cur.execute("select * from train") recs=cur.fetchall() for no,name,start,end in recs: print(no,name,start,end, sep=' | ') print() print('Total Number of Rows: ', cur.rowcount)
cur.close()
conn.close()

Wednesday, 27 August 2025

revision worksheet

 https://drive.google.com/file/d/1wLdSR6VDU9dtdUw4FPUAQS-PCiDHRgnA/view

GRADE 12 PRACTICAL 19

 '''WAP using Python-MySQL connectivity to connect to an existing table(created on MySQL) and perform the following :

1 DISPLAY DETAILS OF FEMALE PASSENGERS WHO ARE MORE THAN 30 YEARS OLD and ALSO THE TOTAL NUMBER OF SUCH PASSENGERS

2.UPDATE TRAIN NO OF A PARTICULAR PASSENGER

3.DELETE RECORD WHERE PASSENGER NAME HAS SHARMA

TABLE : PASSENGER, DATABASE: PRACT19

+------------------------------------------------------+

| PNR | TNO   |    PNAME   | GENDER | AGE | TRAVELDATE |

+------------------------------------------------------+

|P003 | 12015 |S TIWARI    | FEMALE | 22  | 2018-11-10 |

|P004 | 12030 |S K SAXENA  |  MALE  | 42  | 2018-10-12 |

|P005 | 12030 |S SAXENA    | FEMALE | 35  | 2018-10-12 |

|P008 | 12030 |J K SHARMA  |  MALE  | 65  | 2018-05-09 |

|P009 | 12030 |R SHARMA    | FEMALE | 58  | 2018-05-09 |

+------------------------------------------------------+  '''


DO NOT WRITE THE GREY PART IN THE NOTE BOOK. JUST PUT A PIC OF THE TABLE IN THE RECORD.
CREATE DATABASE PRACT19; USE PRACT19; CREATE TABLE PASSENGER ( PNR CHAR(4) PRIMARY KEY, TNO INT, PNAME VARCHAR(30), GENDER CHAR(6), AGE INT, TRAVELDATE DATE );
INSERT INTO PASSENGER VALUES ('P003', 12015, 'S TIWARI', 'FEMALE', 22, '2018-11-10'), ('P004', 12030, 'S K SAXENA', 'MALE', 42, '2018-10-12'), ('P005', 12030, 'S SAXENA', 'FEMALE', 35, '2018-10-12'), ('P008', 12030, 'J K SHARMA', 'MALE', 65, '2018-05-09'), ('P009', 12030, 'R SHARMA', 'FEMALE', 58, '2018-05-09');


WRITE ONLY THE BELOW PYTHON CODE
import mysql.connector as my conn = my.MySQLConnection(host='localhost', user='root', password='123456789', database='lab19') if conn.is_connected(): print('Connected to MySQL successfully!') else: print('Connection is unsuccessful!') cur = conn.cursor(buffered=True) # DISPLAY DETAILS OF FEMALE PASSENGERS WHO ARE MORE THAN 30 YEARS OLD print('''To display the details of female passengers who are more than 30 years old and the count of such passengers:''') age = 30 sex = 'female' cur.execute('SELECT * FROM passenger WHERE age > %s AND gender = %s', (age, sex)) recs = cur.fetchall() count = cur.rowcount for a, b, c, d, e, f in recs: print(a, b, c, d, e, f, sep=' | ') print('Total no. of such passengers:', count) cur.reset() print() # UPDATE TRAIN NO OF A PARTICULAR PASSENGER print('To update train no. of a particular passenger:') pnr = input('Enter your booking PNR: ') cur.execute('SELECT * FROM passenger WHERE pnr = %s', (pnr,)) rec = cur.fetchone() if not rec: print('No such record found!') else: print('Passenger found:', rec) newtno = int(input('Enter new Train No: ')) cur.execute('UPDATE passenger SET tno = %s WHERE pnr = %s', (newtno, pnr)) print('Details updated!') cur.reset() conn.commit() print() # DELETE DATA WITH 'SHARMA' print("To delete data with 'SHARMA':") cur.execute('SELECT * FROM passenger WHERE pnr = %s', (pnr,)) rec = cur.fetchone() if not rec: print('No such record found!') else: cur.execute('DELETE FROM passenger WHERE pname LIKE "%sharma%"') print('Data deleted!') cur.reset() conn.commit() print() # DISPLAY ALL RECORDS cur.execute('SELECT * FROM passenger') recs = cur.fetchall() for a, b, c, d, e, f in recs: print(a, b, c, d, e, f, sep=' | ') # Close resources cur.close() conn.close()



Thursday, 21 August 2025

GRADE 12: PRACTICAL 18

'''WAP using Python-MySQL connectivity to create the given table and insert values. Create a menu driven program for : MENU: 1.DISPLAY DESIRED NUMBER OF RECORDS 2.DISPLAY TOTAL NUMBER OF ROWS 3.UPDATE SALARY 4.SEARCH EMPLOYEES WITH SALARY ABOVE RS. 50000

5.DELETE RECORD

TABLE : EMPLOYEE +-------+---------------+---------+--------+-----+------------+ | EOCDE | ENAME | DEPCODE | salary | AGE | JOINDATE | +-------+---------------+---------+--------+-----+------------+ | 15 | SAMEER SHARMA | 123 | 75000 | 39 | 2007-04-01 | | 21 | RAGVINDER K | 101 | 86000 | 29 | 2005-11-11 | | 81 | RAJESH KUMAR | 119 | 74500 | 48 | 2008-12-11 | | 89 | SANJEEV P | 101 | 92600 | 54 | 2009-01-12 | | 93 | PRAGYA JAIN | 123 | 32000 | 29 | 2006-08-05 | +-------+---------------+---------+--------+-----+------------+ '''


import mysql.connector as my

conn=my.connect(host='localhost',user='root',password='123456')
if conn.is_connected():
    print('Connected to MySQL Successfully')
else:
    print('Connection is unsuccessful')

cur=conn.cursor(buffered=True)#this ensures that the cursor error doesn't occur even if all records are not read
cur.execute('drop database if exists database18')
cur.execute('create database database18')
cur.execute('use database18')

cur.execute('''create table employee
(ECODE int primary key,ENAME char(30),
DEPCODE int, SALARY int, AGE int, JOINDATE date)''')

cur.execute('''insert into employee values
(15,'SAMEER SHARMA',123,75000,39,'2007-04-01'),
(21,'RAGVINDER K',101,86000,29,'2005-11-11'),
(81,'RAJESH KUMAR',119,74500,48,'2008-12-11'),
(89,'SANJEEV P',101,92600,54,'2009-01-12'),
(93,'PRAGYA JAIN',123,32000,29,'2006-08-05')''')
conn.commit()

def menu():
    while True :
        ch=int (input("""
1.DISPLAY DESIRED NUMBER OF RECORDS
2.DISPLAY TOTAL NUMBER OF ROWS
3.UPDATE SALARY
4.SEARCH EMPLOYEES WITH SALARY ABOVE RS. 50000
5.DELETE RECORD
6.EXIT
YOUR CHOICE : """))
        if ch==1:
            disp_many()
        elif ch==2:
            tot_rows()
        elif ch==3:
            update()
        elif ch==4:
            search()
        elif ch==5:
            delete()
        else :
            cur.close()
            conn.close()
            break

def disp_many():
    cur.execute("select * from employee")
    no=int(input("Enter no of records you want to display ? "))
    recs = cur.fetchmany(no)
    for a,b,c,d,e,f in recs:
        print(str(a).ljust(5),b.ljust(20),str(c).ljust(5),str(d).ljust(10),str(e).ljust(5),f)
    cur.reset()

def tot_rows():
    cur.execute("select * from employee")
    recs = cur.fetchall()
    print("Total rows : ",cur.rowcount)
    cur.reset()

def update():
    ecode= int(input("Enter emp code whose sal you want to update"))
    cur.execute("select * from employee where ecode=%s",(ecode,))
    rec = cur.fetchone()
    cur.reset()
    if not rec:
        print('Ecode not found')
        return
    print("Record found : ",rec)
    sal=int(input("Enter revised salary"))
    cur.execute("""update employee set salary = %s
where ecode=%s""",(sal,ecode))
    cur.reset()
    conn.commit()

def search():
    print("Employees with SALARY > 50000")
    cur.execute("select * from employee where salary>50000")
    recs = cur.fetchall()  
    if not recs:
        print('NONE')
        cur.reset()
        return
    for a,b,c,d,e,f in recs:      print(str(a).ljust(5),b.ljust(20),str(c).ljust(5),str(d).ljust(10),str(e).ljust(5),f)
    cur.reset()

def delete():
    ecode= int(input("Enter emp code whose sal you want to delete"))
    cur.execute("select * from employee where ecode=%s",(ecode,))
    rec = cur.fetchone()
    cur.reset()
    if not rec:
        print('Ecode not found')
        return
    print("Record found : ",rec)
    ans=input("Are you sure you want to delete(y/n)")
    if ans=='n':
        return
    cur.execute("delete from employee where ecode=%s",(ecode,))
    cur.reset()
    conn.commit()
  

menu()

Friday, 1 August 2025

GRADE 12 : PRACTICAL 17

Create the tables given below, and perform the given queries 

ORDERS

ITEM

CREATE LAB17;

USE LAB17;

CREATE TABLE Item (

    ItemID INT PRIMARY KEY,
    ItemName VARCHAR(50),
    Category VARCHAR(30),
    Price DECIMAL(10,2),
    StockQty INT
);

INSERT INTO Item (ItemID, ItemName, Category, Price, StockQty) VALUES
(101, 'Pen', 'Stationery', 10.00, 150),
(102, 'Notebook', 'Stationery', 50.00, 100),
(103, 'Water Bottle', 'Accessories', 120.00, 75),
(104, 'Pencil Box', 'Stationery', 80.00, 60),
(105, 'Backpack', 'Bags', 500.00, 30);

CREATE TABLE Orders (
    OrderID INT ,
    OrderDate DATE,
    CustomerName VARCHAR(50),
    ItemID INT,
    Quantity INT,
    PRIMARY KEY(OrderID,ItemID),
    FOREIGN KEY (ItemID) REFERENCES Item(ItemID)
);

INSERT INTO Orders (OrderID, OrderDate, CustomerName, ItemID, Quantity) VALUES
(201, '2025-07-15', 'Riya Sharma', 101, 3),
(202, '2025-07-17', 'Neha Sinha', 102, 2),
(202, '2025-07-17', 'Neha Sinha', 103, 1),
(203, '2025-07-18', 'Isha Verma', 104, 1),
(204, '2025-07-17', 'Kanye West', 103, 1);


1. Show each customer's total bill amount
SELECT OrderID,CustomerName,sum(Quantity*Price) as Total
FROM Orders NATURAL JOIN Item GROUP BY OrderId,CustomerName;

2. Display items where Total quantity ordered per item(across orders) is more than 1
SELECT itemid,itemname,sum(quantity) FROM item NATURAL JOIN orders
GROUP BY itemid,itemname having sum(quantity)>1;

3. Show the order id, orderdate , customer name and item name of the items ordered on 17-07-2025
SELECT orderid,orderdate,customername,itemname FROM orders NATURAL JOIN item
WHERE orderdate='2025-07-17';

4. List all orders with item names in descending order of quantity
SELECT orderid,itemname,quantity FROM orders NATURAL JOIN item
ORDER BY quantity DESC;

5. Decrease the stock for pen by 5
 UPDATE item SET StockQty=StockQty-5 WHERE
 Itemname='Pen';

6. Show categories and number of items in that category sorted by average price descending 
SELECT Category, COUNT(*) as No_of_Items, Avg(Price)
FROM item GROUP BY Category ORDER BY Avg(Price) DESC;

7. Show all items with second letter as 'a'
 SELECT * FROM item WHERE ItemName LIKE '_a%';
 
8. Find the item with the maximum price
SELECT itemName, price FROM item WHERE price =
(SELECT max(price) FROM item);

9. Show the most recently placed order
SELECT * FROM orders WHERE orderdate= (SELECT max(orderdate)
FROM orders);

10. Delete order entries where pencil box is bought.
DELETE FROM orders WHERE ItemId=(SELECT ItemID FROM item WHERE
itemname='pencil box');

Sunday, 27 July 2025

GRADE 12 : PRACTICAL 16

 Create the below tables and perform the required queries:


FURNITURE:


+----+-----------------+--------------+-------------+----------+----------+

| no | itemname        | type         | dateofstock | price    | discount |

+----+-----------------+--------------+-------------+----------+----------+

|  1 | dolphin         | baby cot     | 19-02-2002  |  9500.00 |       20 |

|  2 | decent          | office table | 01-01-2002  | 25000.00 |       30 |

|  3 | comfort zone    | double bed   | 12-01-2002  | 25000.00 |       25 |

|  4 | donald          | baby cot     | 24-02-2002  |  6500.00 |       15 |

|  5 | royal finish    | office table | 20-02-2002  | 18000.00 |       90 |

|  6 | royal tiger     | sofa         | 22-02-2002  | 31000.00 |       30 |

|  7 | economy sitting | sofa         | 13-12-2001  |  9500.00 |       25 |

|  8 | eating paradise | dining table | 19-02-2002  | 11500.00 |       25 |

+----+-----------------+--------------+-------------+----------+----------+  


ARRIVALS:


+----+--------------+------------+-------------+----------+----------+

| no | itemname     | type       | dateofstock | price    | discount |

+----+--------------+------------+-------------+----------+----------+

|  1 | wood comfort | double bed | 23-03-2003  | 25000.00 |       25 |

|  2 | old fox      | sofa       | 20-03-2003  | 17000.00 |       20 |

|  3 | micky        | baby cot   | 1-4-2003    |  7500.00 |       15 |

+----+--------------+------------+-------------+----------+----------+


CREATE STATEMENTS :


create database lab17;

use lab17;


create table furniture(

no int primary key,

itemname varchar(50) not null, 

type varchar(50) not null,

dateofstock date not null,

price decimal(8,2), 

discount numeric(2)

);


create table arrivals(

no int primary key , 

itemname varchar(50) not null, 

type varchar(50) not null,

dateofstock date not null,

price decimal(8,2) not null, 

discount numeric(2) 

);


insert into furniture values 

(1,'dolphin','baby cot','2002-02-19',9500.00,20),

(2,'decent','office table','2002-01-01',25000.00,30),

(3,'comfort zone','double bed','2002-01-12',25000.00,25),

(4,'donald','baby cot','2002-02-24',6500.00,15),

(5,'royal finish','office table','2002-02-20',18000.00,90),

(6,'royal tiger','sofa','2002-02-22',31000.00,30),

(7,'economy sitting','sofa','2001-12-13',9500.00,25),

(8,'eating paradise','dining table','2002-02-19',11500.00,25);


insert into arrivals values 

(1,'wood comfort','double bed','2003-03-23',25000.00,25),

(2,'old fox','sofa','2003-03-20',17000.00,20),

(3,'micky','baby cot','2003-4-1',7500.00,15);



QUERIES

i)List itemnames and types of those items which were stocked in February from the furniture table in descending order of the item name

SELECT itemname, type

FROM furniture

WHERE MONTH(dateofstock) = 2

ORDER BY itemname DESC;


ii)Display item name and date of stock of those items in which the discount percentage is less than 20 or more than 25.

SELECT itemname, dateofstock

FROM furniture

WHERE discount < 20 OR discount > 25;


iii)Display the number of furniture items for each type

SELECT type, COUNT(*) AS item_count FROM furniture GROUP BY type;


iv) Find the maximum discount offered on each furniture type

SELECT type, MAX(discount) AS Max_Discount FROM furniture GROUP BY type.


v)Display furniture items having a price greater than the average price of all arrivals.

SELECT itemname, price

FROM furniture

WHERE price > (SELECT AVG(price) FROM arrivals);


vi)Display furniture types that are not present in the arrivals table
SELECT DISTINCT type
FROM furniture
WHERE type NOT IN (SELECT DISTINCT type FROM arrivals);

vii) Display item no, item name, mrp and the discounted price for all items

SELECT 

    no AS item_no,

    itemname,

    price AS mrp,

    price - (price * discount / 100) AS discounted_price

FROM furniture;


viii)Move all the rows from arrivals into the furniture table UPDATE arrivals SET no=no+(SELECT MAX(no) FROM furniture); INSERT INTO furniture SELECT * FROM arrivals;

DELETE FROM arrivals;


ix)Increase the discount by 5 for all 'sofa' type items in the furniture table.
 UPDATE furniture
SET discount = discount + 5
WHERE type = 'sofa';

x)Remove all furniture items that were stocked before January 1, 2002.
DELETE FROM furniture
WHERE dateofstock < '2002-01-01';