0% found this document useful (0 votes)
3 views

DBMS practical practice

Uploaded by

Pranav
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)
3 views

DBMS practical practice

Uploaded by

Pranav
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/ 34

CREATE TABLE product(

prod_id INT PRIMARY KEY,


prod_name VARCHAR(30) NOT NULL,
prod_brand varchar(20),
prod_catg varchar(20),
prod_cost int,
prod_mfg date,
check (prod_cost>100)
);

DESCRIBE product

DROP TABLE product

CREATE TABLE customer(


cust_id int primary key,
cust_name varchar(30) not null,
cust_city varchar(20),
cust_street varchar(20),
cust_dob date,
age int
);
DESCRIBE customer
DROP TABLE customer

CREATE TABLE order_on(


order_id int primary key,
ord_date date,
order_qty int,
prod_id int references product (prod_id),
cust_id int references customer (cust_id),
mode_pay varchar(20),
order_dod date
);
DESCRIBE order_on
DROP TABLE order_on;

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10001, 'Laptop', 'DELL', 'Electronics', 50000, '01-Jan-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10002, 'Chair', 'Staples', 'Furniture', 5000, '15-Dec-2022')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10003, 'Refrigerator', 'Whirlpool', 'Appliances', 40000, '10-Oct-2023')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10004, 'Sofa', 'Home Centre', 'Furniture', 35000, '23-Aug-2022')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10005, 'Shirt', 'Peter England', 'Clothes', 1500, '24-Jun-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10006, 'Sketch Book', 'Classmate', 'Stationary', 500, '10-Jul-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10007, 'Hibiscus', 'Plantery', 'Plants', 300, '25-Jun-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10008, 'Gold Neklace', 'Kalyan', 'Jewellery', 100000, '23-Nov-2023')
INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)
VALUES (10009, 'Cupboard', 'Steel Case', 'Furniture', 25000, '15-Jul-2015')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10010, 'Earthen Pot', 'Earth', 'Ceramics', 600, '30-Aug-2023')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10011, 'Television', 'Sony', 'Electronics', 10000, '7-Feb-2022')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10012, 'School Bag', 'American Tourister', 'Bags', 3500, '4-July-2023')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10013, 'Mobile', 'Xiomi', 'Electronics', 21000, '8-Aug-2023')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10014, 'Table', 'Ashley Furniture', 'Furniture', 7500, '31-May-2022')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10015, 'Jeans', 'Levi''s', 'Clothes', 1050, '5-Nov-2023')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10016, 'Rose', 'Bloomscape', 'Plants', 1000, '19-Jun-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10017, 'Pencil Box', 'Apsara', 'Stationary', 150, '15-May-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10018, 'Wedding Ring', 'Forever', 'Jewellery', 80000, '17-Sep-2021')
INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)
VALUES (10019, 'Purse', 'Marks and Spencer', 'Bags', 5600, '16-Jan-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10020, 'Cup Set', 'Larah', 'Ceramics', 900, '18-Feb-2024')

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10021, 'Notebook', 'Classmate', 'Stationary', 300, '22-Mar-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10022, 'Headphones', 'Sony', 'Electronics', 4000, '25-Jan-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10023, 'Dining Table', 'Ikea', 'Furniture', 35000, '10-Apr-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10024, 'Microwave', 'LG', 'Appliances', 12000, '14-Oct-2022');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10025, 'Water Bottle', 'Milton', 'Accessories', 700, '28-Feb-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10026, 'Shoes', 'Nike', 'Footwear', 6000, '12-Jun-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10027, 'Cup Set', 'Borosil', 'Ceramics', 950, '11-Mar-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10028, 'Mobile Cover', 'Spigen', 'Accessories', 500, '23-Jan-2024');
INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)
VALUES (10029, 'T-Shirt', 'Puma', 'Clothes', 1200, '7-Aug-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10030, 'Bed', 'Home Centre', 'Furniture', 45000, '16-May-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10031, 'Lamp', 'Philips', 'Electronics', 1500, '29-Jul-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10032, 'Refrigerator', 'Samsung', 'Appliances', 38000, '1-Dec-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10033, 'Desk', 'Urban Ladder', 'Furniture', 8500, '21-Feb-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10034, 'Cup Set', 'Larah', 'Ceramics', 950, '18-Feb-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10035, 'Jeans', 'Wrangler', 'Clothes', 2200, '12-Mar-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10036, 'Plant Pot', 'Planto', 'Plants', 600, '17-May-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10037, 'Perfume', 'Chanel', 'Cosmetics', 10000, '2-Jun-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10038, 'Smartwatch', 'Apple', 'Electronics', 35000, '22-Sep-2023');
INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)
VALUES (10039, 'Pillow', 'Sleepwell', 'Furniture', 800, '14-Apr-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10040, 'Coffee Maker', 'Philips', 'Appliances', 2500, '9-Dec-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10041, 'Pen', 'Reynolds', 'Stationary', 110, '28-Jul-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10042, 'Shampoo', 'Dove', 'Cosmetics', 500, '19-Mar-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10043, 'Speaker', 'JBL', 'Electronics', 3000, '6-May-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10044, 'Dining Chair', 'Ikea', 'Furniture', 3500, '10-Aug-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10045, 'Sketch Pen', 'Faber Castell', 'Stationary', 200, '15-Jun-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10046, 'Bracelet', 'Tanishq', 'Jewellery', 25000, '12-Dec-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10047, 'Bookshelf', 'Godrej', 'Furniture', 7000, '3-Feb-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10048, 'Curtains', 'DDecor', 'Home Decor', 4000, '19-Jan-2024');
INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)
VALUES (10049, 'Laptop Bag', 'HP', 'Bags', 2000, '11-Nov-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10050, 'Couch', 'Urban Ladder', 'Furniture', 30000, '28-Jul-2023');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10051, 'Smartphone', 'Samsung', 'Electronics', 25000, '15-Feb-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10052, 'Refrigerator', 'LG', 'Appliances', 45000, '01-Mar-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10053, 'Dining Table', 'Ikea', 'Furniture', 15000, '20-Feb-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10054, 'Bluetooth Speaker', 'JBL', 'Electronics', 5000, '10-Jan-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10055, 'Microwave Oven', 'Samsung', 'Appliances', 12000, '05-Feb-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10056, 'Washing Machine', 'Whirlpool', 'Appliances', 30000, '25-Mar-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10057, 'Running Shoes', 'Nike', 'Footwear', 7000, '18-Apr-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10058, 'Air Conditioner', 'Voltas', 'Appliances', 35000, '30-May-2024');
INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)
VALUES (10059, 'LED TV', 'Sony', 'Electronics', 50000, '07-Jun-2024');

INSERT INTO product(prod_id, prod_name, prod_brand, prod_catg, prod_cost, prod_mfg)


VALUES (10060, 'Gaming Console', 'PlayStation', 'Electronics', 40000, '15-Jul-2024');

DESCRIBE customer

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1001, 'Ananya Sharma', 'Mumbai', 'Andheri', '13-May-1989', EXTRACT (YEAR
FROM SYSDATE) - '1989');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1002, 'Pratik Paredeshi', 'Pune', 'Hadapsar', '21-Apr-2001', EXTRACT (YEAR
FROM SYSDATE) - '2001');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1003, 'Sanjana Rao', 'Bangalore', 'Whitefield', '10-Jan-1995', EXTRACT(YEAR
FROM SYSDATE) - '1995');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1004, 'Vikas Gupta', 'Delhi', 'Saket', '22-Feb-1987', EXTRACT(YEAR FROM
SYSDATE) - '1987');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1005, 'Neha Singh', 'Chennai', 'Velachery', '15-Mar-1992', EXTRACT(YEAR
FROM SYSDATE) - '1992');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1006, 'Rahul Verma', 'Kolkata', 'Salt Lake', '25-May-1998', EXTRACT(YEAR
FROM SYSDATE) - '1998');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1007, 'Pooja Desai', 'Ahmedabad', 'Navrangpura', '30-Jul-1990',
EXTRACT(YEAR FROM SYSDATE) - '1990');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1008, 'Amit Joshi', 'Hyderabad', 'Banjara Hills', '09-Jun-1993', EXTRACT(YEAR
FROM SYSDATE) - '1993');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1009, 'Ritika Mahajan', 'Chandigarh', 'Sector 17', '04-Oct-1997',
EXTRACT(YEAR FROM SYSDATE) - '1997');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1010, 'Karan Mehta', 'Jaipur', 'Malviya Nagar', '12-Nov-1996', EXTRACT(YEAR
FROM SYSDATE) - '1996');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1011, 'Meera Iyer', 'Thane', 'Ghodbunder Road', '18-Dec-1994', EXTRACT(YEAR
FROM SYSDATE) - '1994');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1012, 'Suresh Patel', 'Surat', 'Adajan', '27-Aug-1991', EXTRACT(YEAR FROM
SYSDATE) - '1991');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1013, 'Alok Tiwari', 'Lucknow', 'Gomti Nagar', '14-Sep-1988', EXTRACT(YEAR
FROM SYSDATE) - '1988');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1014, 'Sneha Kulkarni', 'Nagpur', 'Dharampeth', '23-Jan-1999', EXTRACT(YEAR
FROM SYSDATE) - '1999');
INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)
VALUES (1015, 'Ravi Kapoor', 'Indore', 'Vijay Nagar', '16-Apr-1990', EXTRACT(YEAR
FROM SYSDATE) - '1990');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1016, 'Priya Nair', 'Cochin', 'Fort Kochi', '07-Feb-1985', EXTRACT(YEAR
FROM SYSDATE) - '1985');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1017, 'Aditya Sengupta', 'Bhopal', 'Arera Colony', '19-Mar-1993',
EXTRACT(YEAR FROM SYSDATE) - '1993');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1018, 'Komal Agarwal', 'Guwahati', 'Paltan Bazar', '06-Jul-1986',
EXTRACT(YEAR FROM SYSDATE) - '1986');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1019, 'Mohit Arora', 'Ludhiana', 'Civil Lines', '11-May-1994', EXTRACT(YEAR
FROM SYSDATE) - '1994');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1020, 'Ankita Paul', 'Patna', 'Boring Road', '20-Jun-1992', EXTRACT(YEAR
FROM SYSDATE) - '1992');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1021, 'Gaurav Shah', 'Vadodara', 'Alkapuri', '30-Sep-1990', EXTRACT(YEAR
FROM SYSDATE) - '1990');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1022, 'Swati Gupta', 'Noida', 'Sector 62', '03-Feb-1997', EXTRACT(YEAR FROM
SYSDATE) - '1997');
INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)
VALUES (1023, 'Rohit Bansal', 'Gurgaon', 'DLF Phase 3', '25-Jul-1993', EXTRACT(YEAR
FROM SYSDATE) - '1993');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1024, 'Priyanka Reddy', 'Hyderabad', 'Madhapur', '14-Oct-1992',
EXTRACT(YEAR FROM SYSDATE) - '1992');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1025, 'Rajesh Kumar', 'Ranchi', 'Kanke Road', '18-Dec-1987', EXTRACT(YEAR
FROM SYSDATE) - '1987');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1026, 'Megha Jain', 'Kanpur', 'Swaroop Nagar', '05-Jan-1996', EXTRACT(YEAR
FROM SYSDATE) - '1996');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1027, 'Aman Singh', 'Pune', 'Kothrud', '20-Aug-1989', EXTRACT(YEAR FROM
SYSDATE) - '1989');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1028, 'Nidhi Patel', 'Surat', 'Piplod', '28-Feb-1995', EXTRACT(YEAR FROM
SYSDATE) - '1995');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1029, 'Sanjay Kumar', 'Patna', 'Rajendra Nagar', '19-Nov-1991',
EXTRACT(YEAR FROM SYSDATE) - '1991');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1030, 'Nisha Verma', 'Jaipur', 'C-Scheme', '12-May-1988', EXTRACT(YEAR
FROM SYSDATE) - '1988');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1031, 'Ajay Thakur', 'Bhopal', 'Kolar Road', '23-Apr-1990', EXTRACT(YEAR
FROM SYSDATE) - '1990');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1032, 'Shivani Agarwal', 'Nagpur', 'Ramdaspeth', '07-Jun-1992',
EXTRACT(YEAR FROM SYSDATE) - '1992');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1033, 'Vivek Pandey', 'Varanasi', 'Assi Ghat', '02-Jan-1991', EXTRACT(YEAR
FROM SYSDATE) - '1991');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1034, 'Shreya Kapoor', 'Faridabad', 'Sector 15', '17-Jul-1994', EXTRACT(YEAR
FROM SYSDATE) - '1994');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1035, 'Ankit Saxena', 'Meerut', 'Shastri Nagar', '05-Aug-1993', EXTRACT(YEAR
FROM SYSDATE) - '1993');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1036, 'Rekha Singh', 'Lucknow', 'Hazratganj', '20-Feb-1990', EXTRACT(YEAR
FROM SYSDATE) - '1990');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1037, 'Naveen Arora', 'Jalandhar', 'Model Town', '14-Dec-1995',
EXTRACT(YEAR FROM SYSDATE) - '1995');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1038, 'Richa Joshi', 'Dehradun', 'Rajpur Road', '01-Oct-1988', EXTRACT(YEAR
FROM SYSDATE) - '1988');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1039, 'Rajiv Sinha', 'Raipur', 'Tatibandh', '26-Mar-1994', EXTRACT(YEAR
FROM SYSDATE) - '1994');
INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)
VALUES (1040, 'Mona Sharma', 'Amritsar', 'Ranjit Avenue', '03-Apr-1987',
EXTRACT(YEAR FROM SYSDATE) - '1987');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1041, 'Aakash Mehta', 'Thane', 'Vartak Nagar', '18-Jun-1996', EXTRACT(YEAR
FROM SYSDATE) - '1996');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1042, 'Ravi Shukla', 'Gwalior', 'Phool Bagh', '27-Aug-1992', EXTRACT(YEAR
FROM SYSDATE) - '1992');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1043, 'Sunita Rao', 'Vishakhapatnam', 'Daba Gardens', '09-May-1990',
EXTRACT(YEAR FROM SYSDATE) - '1990');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1044, 'Rajendra Reddy', 'Warangal', 'Hanamkonda', '13-Sep-1986',
EXTRACT(YEAR FROM SYSDATE) - '1986');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1045, 'Vandana Tripathi', 'Aligarh', 'Rasal Ganj', '08-Jun-1995', EXTRACT(YEAR
FROM SYSDATE) - '1995');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1046, 'Rohan Desai', 'Nashik', 'Gangapur Road', '29-Jan-1993', EXTRACT(YEAR
FROM SYSDATE) - '1993');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1047, 'Anjali Singh', 'Agra', 'Dayal Bagh', '11-Oct-1990', EXTRACT(YEAR
FROM SYSDATE) - '1990');
INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)
VALUES (1048, 'Arun Pillai', 'Kochi', 'Marine Drive', '21-Nov-1988', EXTRACT(YEAR
FROM SYSDATE) - '1988');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1049, 'Pallavi Verma', 'Bhubaneswar', 'Sahid Nagar', '24-Feb-1991',
EXTRACT(YEAR FROM SYSDATE) - '1991');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1050, 'Siddharth Rao', 'Mysore', 'Vijayanagar', '15-Aug-1994', EXTRACT(YEAR
FROM SYSDATE) - '1994');

INSERT INTO customer (cust_id, cust_name, cust_city, cust_street, cust_dob, age)


VALUES (1051, 'Malhar Shinde', 'Pune', 'Koregaon Park', '24-Sep-1996', EXTRACT(YEAR
FROM SYSDATE) - '1996');

ALTER TABLE customer


ADD mob_no VARCHAR(15);

UPDATE customer SET mob_no = '9876543210' WHERE cust_id = 1001;


UPDATE customer SET mob_no = '9123456789' WHERE cust_id = 1002;
UPDATE customer SET mob_no = '8987654321' WHERE cust_id = 1003;
UPDATE customer SET mob_no = '9786543210' WHERE cust_id = 1004;
UPDATE customer SET mob_no = '9871234560' WHERE cust_id = 1005;
UPDATE customer SET mob_no = '9765432109' WHERE cust_id = 1006;
UPDATE customer SET mob_no = '9456781230' WHERE cust_id = 1007;
UPDATE customer SET mob_no = '9345678901' WHERE cust_id = 1008;
UPDATE customer SET mob_no = '9234567890' WHERE cust_id = 1009;
UPDATE customer SET mob_no = '9123456780' WHERE cust_id = 1010;
UPDATE customer SET mob_no = '9012345678' WHERE cust_id = 1011;
UPDATE customer SET mob_no = '8901234567' WHERE cust_id = 1012;
UPDATE customer SET mob_no = '8790123456' WHERE cust_id = 1013;
UPDATE customer SET mob_no = '8689012345' WHERE cust_id = 1014;
UPDATE customer SET mob_no = '8578901234' WHERE cust_id = 1015;
UPDATE customer SET mob_no = '8467890123' WHERE cust_id = 1016;
UPDATE customer SET mob_no = '8356789012' WHERE cust_id = 1017;
UPDATE customer SET mob_no = '8245678901' WHERE cust_id = 1018;
UPDATE customer SET mob_no = '8134567890' WHERE cust_id = 1019;
UPDATE customer SET mob_no = '8023456789' WHERE cust_id = 1020;
UPDATE customer SET mob_no = '7912345678' WHERE cust_id = 1021;
UPDATE customer SET mob_no = '7801234567' WHERE cust_id = 1022;
UPDATE customer SET mob_no = '7690123456' WHERE cust_id = 1023;
UPDATE customer SET mob_no = '7589012345' WHERE cust_id = 1024;
UPDATE customer SET mob_no = '7478901234' WHERE cust_id = 1025;
UPDATE customer SET mob_no = '7367890123' WHERE cust_id = 1026;
UPDATE customer SET mob_no = '7256789012' WHERE cust_id = 1027;
UPDATE customer SET mob_no = '7145678901' WHERE cust_id = 1028;
UPDATE customer SET mob_no = '7034567890' WHERE cust_id = 1029;
UPDATE customer SET mob_no = '6923456789' WHERE cust_id = 1030;
UPDATE customer SET mob_no = '6812345678' WHERE cust_id = 1031;
UPDATE customer SET mob_no = '6701234567' WHERE cust_id = 1032;
UPDATE customer SET mob_no = '6590123456' WHERE cust_id = 1033;
UPDATE customer SET mob_no = '6489012345' WHERE cust_id = 1034;
UPDATE customer SET mob_no = '6378901234' WHERE cust_id = 1035;
UPDATE customer SET mob_no = '6267890123' WHERE cust_id = 1036;
UPDATE customer SET mob_no = '6156789012' WHERE cust_id = 1037;
UPDATE customer SET mob_no = '6045678901' WHERE cust_id = 1038;
UPDATE customer SET mob_no = '5934567890' WHERE cust_id = 1039;
UPDATE customer SET mob_no = '5823456789' WHERE cust_id = 1040;
UPDATE customer SET mob_no = '5712345678' WHERE cust_id = 1041;
UPDATE customer SET mob_no = '5601234567' WHERE cust_id = 1042;
UPDATE customer SET mob_no = '5490123456' WHERE cust_id = 1043;
UPDATE customer SET mob_no = '5389012345' WHERE cust_id = 1044;
UPDATE customer SET mob_no = '5278901234' WHERE cust_id = 1045;
UPDATE customer SET mob_no = '5167890123' WHERE cust_id = 1046;
UPDATE customer SET mob_no = '5056789012' WHERE cust_id = 1047;
UPDATE customer SET mob_no = '4945678901' WHERE cust_id = 1048;
UPDATE customer SET mob_no = '4834567890' WHERE cust_id = 1049;
UPDATE customer SET mob_no = '4723456789' WHERE cust_id = 1050;

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100001, '15-Jan-2023', 1, 10010, 1023, 'Credit Card', '20-Jan-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100002, '22-Feb-2022', 7, 10035, 1002, 'Debit Card', '25-Feb-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100003, '10-Mar-2023', 1, 10022, 1035, 'Net Banking', '15-Mar-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100004, '05-Apr-2023', 9, 10001, 1044, 'UPI', '08-Apr-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100005, '19-May-2022', 3, 10025, 1029, 'Cash on Delivery', '22-May-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100006, '13-Jun-2024', 2, 10048, 1018, 'Credit Card', '18-Jun-2024');
INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,
order_dod)
VALUES (100007, '25-Jul-2023', 1, 10017, 1040, 'Debit Card', '29-Jul-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100008, '08-Aug-2024', 4, 10013, 1015, 'Net Banking', '12-Aug-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100009, '30-Sep-2022', 5, 10031, 1039, 'UPI', '05-Oct-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100010, '12-Oct-2023', 2, 10004, 1005, 'Cash on Delivery', '18-Oct-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100011, '17-Nov-2022', 1, 10046, 1022, 'Credit Card', '22-Nov-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100012, '23-Dec-2023', 3, 10009, 1006, 'Debit Card', '28-Dec-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100013, '09-Jan-2022', 2, 10002, 1011, 'Net Banking', '15-Jan-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100014, '14-Feb-2023', 1, 10012, 1017, 'UPI', '19-Feb-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100015, '20-Mar-2024', 4, 10005, 1004, 'Cash on Delivery', '25-Mar-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100016, '28-Apr-2022', 1, 10033, 1001, 'Credit Card', '03-May-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100017, '11-May-2023', 3, 10018, 1047, 'Debit Card', '16-May-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100018, '07-Jun-2024', 2, 10011, 1032, 'Net Banking', '13-Jun-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100019, '22-Jul-2023', 1, 10030, 1028, 'UPI', '27-Jul-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100020, '05-Aug-2024', 1, 10047, 1050, 'Cash on Delivery', '10-Aug-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100021, '15-Jan-2023', 1, 10006, 1014, 'Credit Card', '20-Jan-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100022, '22-Feb-2022', 7, 10024, 1049, 'Debit Card', '25-Feb-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100023, '10-Mar-2023', 1, 10041, 1033, 'Net Banking', '15-Mar-2023');
INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,
order_dod)
VALUES (100024, '05-Apr-2023', 9, 10023, 1020, 'UPI', '08-Apr-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100025, '19-May-2022', 3, 10007, 1041, 'Cash on Delivery', '22-May-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100026, '13-Jun-2024', 2, 10050, 1031, 'Credit Card', '18-Jun-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100027, '25-Jul-2023', 1, 10029, 1016, 'Debit Card', '29-Jul-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100028, '08-Aug-2024', 4, 10014, 1007, 'Net Banking', '12-Aug-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100029, '30-Sep-2022', 5, 10045, 1008, 'UPI', '05-Oct-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100030, '12-Oct-2023', 2, 10027, 1019, 'Cash on Delivery', '18-Oct-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100031, '17-Nov-2022', 1, 10008, 1003, 'Credit Card', '22-Nov-2022');
INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,
order_dod)
VALUES (100032, '23-Dec-2023', 3, 10038, 1043, 'Debit Card', '28-Dec-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100033, '09-Jan-2022', 2, 10036, 1046, 'Net Banking', '15-Jan-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100034, '14-Feb-2023', 1, 10040, 1038, 'UPI', '19-Feb-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100035, '20-Mar-2024', 4, 10019, 1042, 'Cash on Delivery', '25-Mar-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100036, '28-Apr-2022', 1, 10034, 1027, 'Credit Card', '03-May-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100037, '11-May-2023', 3, 10020, 1012, 'Debit Card', '16-May-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100038, '07-Jun-2024', 2, 10032, 1010, 'Net Banking', '13-Jun-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100039, '22-Jul-2023', 1, 10026, 1030, 'UPI', '27-Jul-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100040, '05-Aug-2024', 1, 10028, 1048, 'Cash on Delivery', '10-Aug-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100041, '20-Sep-2023', 2, 10049, 1026, 'Credit Card', '25-Sep-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100042, '15-Oct-2022', 1, 10016, 1013, 'Debit Card', '20-Oct-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100043, '25-Nov-2023', 4, 10037, 1045, 'Net Banking', '30-Nov-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100044, '05-Dec-2024', 1, 10042, 1036, 'UPI', '10-Dec-2024');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100045, '15-Jan-2023', 1, 10043, 1009, 'Cash on Delivery', '20-Jan-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100046, '25-Feb-2022', 2, 10044, 1042, 'Credit Card', '02-Mar-2022');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100047, '05-Mar-2023', 3, 10003, 1024, 'Debit Card', '10-Mar-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100048, '15-Apr-2024', 2, 10015, 1037, 'Net Banking', '20-Apr-2024');
INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,
order_dod)
VALUES (100049, '25-May-2023', 1, 10039, 1045, 'UPI', '30-May-2023');

INSERT INTO order_on (order_id, ord_date, order_qty, prod_id, cust_id, mode_pay,


order_dod)
VALUES (100050, '05-Jun-2024', 2, 10021, 1034, 'Cash on Delivery', '10-Jun-2024');

DELETE FROM customer WHERE cust_id = 1001;

'Display all products with category electronics'


SELECT * FROM product
WHERE prod_catg = 'Electronics';

'Display all products with category electronics and clothing'


SELECT * FROM product
WHERE prod_catg = 'Electronics' or prod_catg = 'Clothes';

'Display the details of all products of which the cost is more than 1500'
SELECT * FROM product
WHERE prod_cost > 1500;

'Display the details of all products of which the cost is more than 1500 but less than 25000'
SELECT * FROM product
WHERE prod_cost > 1500 and prod_cost < 25000;

'Display the details of all products of which the cost is more than the products of category
clothing'
SELECT * FROM product
WHERE prod_cost > (SELECT MAX(prod_cost) FROM product WHERE prod_catg =
'Clothes');
'Display the details of all products which are manufactured after 30th June 2023'
SELECT * FROM product
WHERE prod_mfg > '30-Jun-2023';

'Display all products whose product name starts with character "S"'
SELECT * FROM product
WHERE SUBSTR(prod_name, 1, 1) = 'S';

'Display all products whose product name has character "t"'


select * from product where prod_name like '%t%'

'Display the details of all products which have the same brand and cost is more than 2000'
SELECT * FROM product
WHERE prod_brand IN (SELECT prod_brand FROM product GROUP BY prod_brand
HAVING COUNT(*) > 1) and prod_cost > 2000;

'Display the details of all products of which the cost is more than the cost of products with
brand <most frequentlly occured>'
SELECT * FROM product
WHERE prod_cost > (
SELECT MAX(prod_cost)
FROM product
WHERE prod_brand = (
SELECT prod_brand
FROM (
SELECT prod_brand, COUNT(*) AS brand_count
FROM product
GROUP BY prod_brand
ORDER BY brand_count DESC
)
WHERE ROWNUM = 1
)
);

SELECT * FROM product


WHERE prod_cost IN (SELECT prod_cost FROM product WHERE prod_catg = 'Clothes')

SELECT * FROM product


WHERE prod_cost NOT IN (SELECT prod_cost FROM product WHERE prod_catg =
'Clothes')

SELECT * FROM product WHERE prod_cost > 50000

SELECT * FROM product WHERE prod_catg = 'Electronics'

SELECT * FROM product


WHERE prod_cost > ALL (SELECT prod_cost FROM product WHERE prod_catg =
'Clothes')

SELECT * FROM product


WHERE prod_cost >= SOME (SELECT prod_cost FROM product WHERE prod_catg =
'Clothes') AND (prod_catg <> 'Clothes')

SELECT * FROM product


WHERE prod_cost = SOME (SELECT prod_cost FROM product WHERE prod_catg =
'Clothes')

SELECT * FROM product


WHERE prod_id NOT IN (SELECT prod_id FROM order_on)

SELECT * FROM customer c


WHERE EXISTS (SELECT 1 FROM order_on o WHERE o.cust_id = c.cust_id);

SELECT * FROM customer c


WHERE NOT EXISTS (SELECT 1 FROM order_on o WHERE o.cust_id = c.cust_id);

'Display customer details who have purchased chair using nested query'
SELECT * FROM customer
WHERE cust_id = (SELECT cust_id FROM order_on WHERE prod_id = (SELECT prod_id
FROM product WHERE prod_name = 'Chair'))

'Display customer details who have purchased <specific object> using join'
SELECT customer.* FROM customer
JOIN order_on ON customer.cust_id = order_on.cust_id
JOIN product ON order_on.prod_id = product.prod_id
WHERE product.prod_name = 'Chair';

'Display product details purchased by <person name> using join'


SELECT product.* FROM product
JOIN order_on ON product.prod_id = order_on.prod_id
JOIN customer ON order_on.cust_id = customer.cust_id
WHERE customer.cust_name = 'Pratik Paredeshi';

'Display customer details who have purchased <specific catg> using join'
SELECT customer.* FROM customer
JOIN order_on ON customer.cust_id = order_on.cust_id
JOIN product ON order_on.prod_id = product.prod_id
WHERE product.prod_catg = 'Furniture';
'Display product details purchased by people age less than 30 using join'
SELECT product.* FROM product
JOIN order_on ON product.prod_id = order_on.prod_id
JOIN customer ON order_on.cust_id = customer.cust_id
WHERE customer.age < 30;

'Display customer details who have purchased items with cost more than 25000 using join'
SELECT customer.* FROM customer
JOIN order_on ON customer.cust_id = order_on.cust_id
JOIN product ON order_on.prod_id = product.prod_id
WHERE product.prod_cost > 25000;

'Display the names and contact number whose customer id is same as 1005'
SELECT cust_name, mob_no FROM customer
WHERE cust_id = 1005

'Display the min, max, avg, sum of cost all products'


SELECT MAX(prod_cost) as maximum_cost, MIN(prod_cost) as minimum_cost,
AVG(prod_cost) as average_cost, SUM (prod_cost) as total_cost FROM product

'Display the category wise avg cost of all product'


SELECT prod_catg as category, AVG(prod_cost) as average_cost FROM product
GROUP BY prod_catg

'Dislay the brand wise avg cost of all products'


SELECT prod_brand, AVG(prod_cost) FROM product
GROUP BY prod_brand

'Display the names of products of which the cost is more than the average cost of the products
of clothing category'
SELECT * FROM product WHERE prod_cost > (SELECT AVG(prod_cost) FROM product
WHERE prod_catg = 'Clothes')

'Display the name of the product which has 2nd max cost (By using nested query only)'
SELECT * FROM product WHERE prod_cost = (SELECT MAX(prod_cost)FROM product
WHERE prod_cost < (SELECT MAX(prod_cost) FROM product WHERE prod_cost))

'Display the category of all products for which more than 3 products are available'
SELECT p.prod_catg, SUM(o.order_qty) as total_order_qty
FROM product p
JOIN order_on o ON p.prod_id = o.prod_id
GROUP BY p.prod_catg
HAVING SUM(o.order_qty) > 3;

'Display the catgories and a total count available of available products'


SELECT p.prod_catg, SUM(o.order_qty) as total_order_qty
FROM product p
JOIN order_on o ON p.prod_id = o.prod_id
GROUP BY p.prod_catg

'Display the names of the cost of all products of which the cost is less than the max cost of
the product of electronic category'
SELECT prod_name FROM product WHERE prod_cost < (SELECT MAX(prod_cost)
FROM product WHERE prod_catg = 'Electronics')

'Display the details of product which are not ordered'


SELECT p.*
FROM product p
LEFT JOIN order_on o ON p.prod_id = o.prod_id
WHERE o.prod_id IS NULL;

'Diplay the details of all products whose mode of pay is not UPI'
SELECT p.* FROM product p, order_on o WHERE o.prod_id = p.prod_id AND
o.mode_pay != 'UPI'

'Diplay the details of all customers whose mode of pay is not UPI'
SELECT c.* FROM customer c, order_on o WHERE o.cust_id = c.cust_id AND
o.mode_pay != 'UPI'

'Diplay the details of all products whose mode of pay is UPI'


SELECT p.* FROM product p, order_on o WHERE o.prod_id = p.prod_id AND
o.mode_pay = 'UPI'

'Diplay the details of all customers whose mode of pay is UPI'


SELECT c.* FROM customer c, order_on o WHERE o.cust_id = c.cust_id AND
o.mode_pay != 'UPI'

'Display the deatils of products ordered in more than 5 quantity'


SELECT p.prod_id ,SUM(o.order_qty) as total_order_qty
FROM product p
JOIN order_on o ON p.prod_id = o.prod_id
GROUP BY p.prod_id
HAVING SUM(o.order_qty) > 5;

'Display the product name, brand of all products ordered in year 2023'
SELECT p.prod_name AS NAME, p.prod_brand AS BRAND, EXTRACT(YEAR FROM
o.ord_date) AS order_date
FROM product p
JOIN order_on o ON p.prod_id = o.prod_id
WHERE EXTRACT(YEAR FROM o.ord_date) = 2023

'Display the list of categories of the products available in store'


SELECT p.prod_catg AS category, COUNT(p.prod_id) AS quantity
FROM product p
LEFT JOIN order_on o ON p.prod_id = o.prod_id
WHERE o.prod_id IS NULL
GROUP BY prod_catg

'Display the names of product and their total cost'


SELECT p.prod_name AS NAME, p.prod_cost AS COST, (o.order_qty * p.prod_cost) AS
total_cost FROM product p
JOIN order_on o ON p.prod_id = o.prod_id

DESCRIBE order_on

'Show customers and their corresponding orders with product details'


CREATE VIEW customer_orders AS
SELECT c.cust_id, c.cust_name, c.mob_no, o.order_id, o.ord_date, p.prod_name,
p.prod_cost, o.order_qty, (p.prod_cost * o.order_qty) AS total_amount
FROM customer c
JOIN order_on o ON c.cust_id = o.cust_id
JOIN product p ON o.prod_id = p.prod_id;

SELECT * FROM customer_orders

' display all customer contact details along with their city and age.'
CREATE VIEW customer_contact_info AS
SELECT cust_id, cust_name, mob_no, cust_city, cust_street, age
FROM customer;

SELECT * FROM customer_contact_info

'view will summarize orders by date, showing the total quantity ordered on each day and the
most frequent payment mode used.'
CREATE VIEW orders_summary_by_date AS
SELECT ord_date, COUNT(order_id) AS total_orders, SUM(order_qty) AS total_quantity,
mode_pay
FROM order_on
GROUP BY ord_date, mode_pay;

SELECT * FROM orders_summary_by_date

'view shows the details of all available products (where prod_cost is greater than 100).'
CREATE VIEW available_products AS
SELECT prod_id, prod_name, prod_brand, prod_catg,prod_cost, prod_mfg
FROM product
WHERE prod_cost > 100;

SELECT *FROM available_products

'view will show the details of the orders placed, along with the expected delivery date.'
CREATE VIEW order_delivery_status AS
SELECT o.order_id,c.cust_name,p.prod_name,o.ord_date AS order_date,o.order_dod AS
delivery_date
FROM order_on o
JOIN customer c ON o.cust_id = c.cust_id
JOIN product p ON o.prod_id = p.prod_id;

SELECT * FROM order_delivery_status

'Displays the total spending of each customer by calculating the total amount they spent
across all orders.'
CREATE VIEW customer_spending AS
SELECT c.cust_id, c.cust_name, SUM(p.prod_cost * o.order_qty) AS total_spent
FROM customer c
JOIN order_on o ON c.cust_id = o.cust_id
JOIN product p ON o.prod_id = p.prod_id
GROUP BY c.cust_id, c.cust_name;

SELECT * FROM customer_spending

'Shows the most popular products by calculating the total quantity sold for each product.'
CREATE VIEW top_selling_products AS
SELECT p.prod_id, p.prod_name, SUM(o.order_qty) AS total_quantity_sold
FROM product p
JOIN order_on o ON p.prod_id = o.prod_id
GROUP BY p.prod_id, p.prod_name
ORDER BY total_quantity_sold DESC;

SELECT * FROM top_selling_products

'Summarizes product sales by category, showing the total quantity sold and revenue generated
for each category.'
CREATE VIEW product_sales_by_category AS
SELECT p.prod_catg, SUM(o.order_qty) AS total_quantity_sold, SUM(p.prod_cost *
o.order_qty) AS total_revenue
FROM product p
JOIN order_on o ON p.prod_id = o.prod_id
GROUP BY p.prod_catg;

SELECT * FROM product_sales_by_category

'Displays a list of customers who have upcoming birthdays.'


CREATE VIEW customer_birthday_list AS
SELECT cust_id, cust_name, cust_dob, cust_city, mob_no
FROM customer
WHERE TO_CHAR(cust_dob, 'MM') = TO_CHAR(SYSDATE, 'MM')
AND TO_CHAR(cust_dob, 'DD') >= TO_CHAR(SYSDATE, 'DD');

SELECT * FROM customer_birthday_list

'Shows all orders that have been placed but are yet to be delivered (where the delivery date is
in the future or null).'
CREATE VIEW pending_orders AS
SELECT o.order_id, c.cust_name, p.prod_name, o.ord_date, o.order_dod AS
expected_delivery
FROM order_on o
JOIN customer c ON o.cust_id = c.cust_id
JOIN product p ON o.prod_id = p.prod_id
WHERE o.order_dod >= SYSDATE OR o.order_dod IS NULL;

SELECT * FROM pending_orders

'Lists customers who have placed more than a certain number of orders.'
CREATE VIEW frequent_customers AS
SELECT c.cust_id, c.cust_name, COUNT(o.order_id) AS total_orders
FROM customer c
JOIN order_on o ON c.cust_id = o.cust_id
GROUP BY c.cust_id, c.cust_name
HAVING COUNT(o.order_id) > 1; -- Replace '5' with the desired threshold for frequent
customers

SELECT * FROM frequent_customers

CREATE USER C##trigger_user IDENTIFIED BY trigger123;


GRANT CONNECT, RESOURCE TO C##trigger_user;
'Trigger to Auto-Update the age in the customer table based on cust_dob'
CREATE OR REPLACE TRIGGER trg_update_age
BEFORE INSERT OR UPDATE ON customer
FOR EACH ROW
BEGIN
:NEW.age := TRUNC(MONTHS_BETWEEN(SYSDATE, :NEW.cust_dob) / 12);
END;
/

SELECT USER FROM dual;


SELECT owner, table_name
FROM all_tables
WHERE table_name IN ('ORDER_ON', 'PRODUCT', 'CUSTOMER');

GRANT SELECT ON SYS.ORDER_ON TO C##TRIGGER_USER;


GRANT SELECT ON SYS.PRODUCT TO C##TRIGGER_USER;
GRANT SELECT ON SYS.CUSTOMER TO C##TRIGGER_USER;

ALTER USER C##TRIGGER_USER QUOTA 100M ON USERS;

-- Connect as SYS or the schema where the customer table exists


CREATE TABLE C##TRIGGER_USER.customer AS
SELECT * FROM sys.customer; -- Replace 'sys.customer' with the correct schema.table if
needed

-- Connect as SYS or the schema where the customer table exists


CREATE TABLE C##TRIGGER_USER.order_on AS
SELECT * FROM sys.order_on; -- Replace 'sys.customer' with the correct schema.table if
needed

-- Connect as SYS or the schema where the customer table exists


CREATE TABLE C##TRIGGER_USER.product AS
SELECT * FROM sys.product; -- Replace 'sys.customer' with the correct schema.table if
needed

SELECT * FROM order_on

You might also like