0% found this document useful (0 votes)
43 views92 pages

9 Allqueriescompleted 1 Indocument

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)
43 views92 pages

9 Allqueriescompleted 1 Indocument

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/ 92

TITLE PageNo.

ABSTRACT…………….……………………..………………… i
CHAPTER 1. INTRODUCTION
1.1 Introduction to the topic…………………………………........ 1
1.2 Problem Statement……………………………………………. 1
1.3 Objectives…………………………………………………….. 2
CHAPTER 2. DATABASE DESIGN
2.1 List of Attributes, entities and relationship…………………… 3-7
2.2 E-R Diagram………………………………………………….. 8-8
CHAPTER 3. RELATIONAL MODEL
3.1 Database languages……………………………………………. 9-10
3.2 Table Description……………………………………………… 10-13
3.3 Relational Database Scheme………………………………….. 14-14
3.4 Relational Queries……………………………………………. 14-42
CHAPTER 4. CONCLUSION AND FUTUREWORK
4.1 Conclusion………………………………………………………. 43-43
4.2 Future Work…………………………………………………….. 44-44

ii
CHAPTER 1. INTRODUCTION

Introduction to the topic

Online shopping databases play a critical role in simplifying the consumer journey by offering
comprehensive product catalogs. These catalogs contain a wide array of products, allowing users
to easily search, browse, and select items of interest. Detailed information, including descriptions,
specifications, pricing, and availability, enables informed decision-making, empowering
customers to make confident purchases. By providing a user-friendly interface and efficient
navigation tools, online shopping databases optimize the browsing experience, ensuring that
shoppers can find the desired products quickly and effortlessly.

In addition to facilitating product discovery, online shopping databases streamline the checkout
process, ensuring secure and hassle-free transactions. These databases integrate with secure
payment gateways, accommodating various payment methods while prioritizing the protection
of sensitive customer information. Robust security measures, such as encryption protocols and
adherence to industry standards, instill confidence in users, fostering trust and credibility.
Furthermore, online shopping databases often leverage customer data and browsing history to
offer personalized recommendations, enhancing the shopping experience and guiding customers
towards relevant products that align with their preferences.

Problem Statement

Despite the increasing popularity of online shopping, there are several challenges that need to
be addressed to optimize the online retail experience. The existing problem lies in the lack of
efficient and user-friendly online shopping databases that can provide comprehensive product
catalogs, streamlined checkout processes, and personalized recommendations. This leads to
frustration and inefficiency for consumers who struggle to find desired products, experience
insecure transactions, and lack personalized guidance during their online shopping journey.
Therefore, there is a pressing need to develop robust online shopping databases that can
effectively address these challenges and enhance the overall user experience.

1
Objective

Objectives of Online Shopping Database:

i. Provide a Comprehensive Product Catalog: The primary objective of an online shopping database
is to offer a comprehensive and up-to-date product catalog. This involves organizing and
maintaining a vast array of products, including detailed information such as descriptions,
specifications, pricing, and availability. The database should enable efficient search, browsing, and
filtering functionalities to allow users to easily locate and explore the products they are interested
in.
ii. Ensure Secure and Seamless Checkout Processes: Another objective is to prioritize the security and
seamlessness of the checkout process. The online shopping database should integrate with secure
payment gateways, implementing robust encryption techniques to protect customer data during
transactions. It should provide multiple payment options to accommodate various user preferences,
ensuring a frictionless experience. Streamlining the checkout process will contribute to building
trust and confidence among users, encouraging them to complete their purchases.
iii. Personalize Recommendations: Online shopping databases should incorporate personalized
recommendation systems to enhance the user experience. By leveraging customer preferences,
browsing history, and behavior patterns, the database can generate tailored product
recommendations. This objective aims to guide users towards relevant products that align with their
interests, increasing the chances of discovering new items and improving overall customer
satisfaction.
iv. Implement Efficient Order Tracking and Inventory Management: An important objective is to
implement an efficient order tracking system that allows users to monitor the progress of their
purchases from placement to delivery. This provides transparency and reassurance to customers,
reducing uncertainty and enhancing the overall shopping experience. Additionally, the database
should automatically update stock levels and manage inventory to ensure accurate product
availability information, minimizing the risk of overselling or backordering.
v. Enhance User Satisfaction and Foster Customer Loyalty: Ultimately, the objective of an online
shopping database is to enhance user satisfaction and foster long-term customer loyalty. By
providing a seamless, secure, and personalized shopping experience, the database aims to create a
positive impression on users, encouraging them to return for future purchases and recommend the
platform to others. This objective focuses on building strong relationships with customers, driving
repeat business, and establishing a loyal customer base.

By addressing these objectives, online shopping databases can optimize the online shopping experience,
improve customer satisfaction, and contribute to the success of e-commerce platforms.

2
CHAPTER 2. DATABASE DESIGN

List of Attributes, entities and relationship

1. Entity Name: Products

Attributes Type
Product_id int
Product_Name Varchar(40)
Description Varchar(40)
Price Money
Stock_Quantity Varchar(50)
Category_id int

2. Entity Name: Categories

Attributes Type
Category_id int
Category_name unique

3. Entity Name: Customers

Attributes Type
Cid int
CName Varchar(400)
Cage int
CMobile Varchar(10)
CEmail Varchar(300)

4. Entity Name: Orders

Attributes Type
Order_id int
Customer_id int
Order_date date
Total_amount int

3
5. Entity Name: Transactions

Attributes Type

Transaction_id int
Order_id int
Payment_date Date
Payment_Method Varchar(30)
Amount int

6. Entity Name: OrderItems

Attributes Type
Order_id int
Product_id Int
Quantity int
Price money

7. Entity Name: Reviews

Attributes Type
Review id int
Customer_id int
Product_id int
Rating int
Comment Varchar(40)
Review_Date Date

8. Entity Name: Addressess

Attributes Type
Customer_id int
C_address Varchar(50)
City Varchar(40)

4
9. Entity Name: Wishlist

Attributes Type
Wishlist_id int
Customer_id int
Product_id int
Wishlist_Date Date

10. Entity Name: Cart

Attributes Type
Cart_id int
Customer_id int
Product_id int
Cart_Date Date
Quantity int

11. Entity Name: Promotions

Attributes Type
Promotion_id int
Promotion_Name Varchar(50)
Promotion_Start_Date Date
Promotion_End_Date Date
Discount_Percentage Varchar(25)

12. Entity Name: Brands

Attributes Type
Brand_id int
Brand_name Varchar(25)

5
2.1.1 Entities and their relationships:

The above diagram is a simple representation of entities which shows the connectivity
between all the entities and the relationship between various entities

To know in detail about the types of relationships that exist between all the entities and to
know the different attributes that describes about the entity we design ER(entity relation)
diagram.

6
2.2 E-R Diagram

7
CHAPTER 3. RELATIONAL MODEL

Database languages
Four categories of database languages :
1. Data definition language (DDL)
Data definition language (DDL) creates the framework of the database by specifying the
database schema, which is the structure that represents the organization of data. Its common
uses include the creation and alteration of tables, files, indexes and columns within the
database. This language also allows users to rename or drop the existingdatabase or its
components.
Here's a list of DDL statements:
• CREATE: Creates a new database or object, such as a table, index or column.
• ALTER: Changes the structure of the database or object.
• DROP: Deletes the database or existing objects.
• RENAME: Renames the database or existing objects.

2. Data manipulation language (DML)


Data manipulation language (DML) provides operations that handle user requests, offering
a way to access and manipulate the data that users store within a database. Its common
functions include inserting, updating and retrieving data from the database.
Here's a list of DML statements:
• INSERT: Adds new data to the existing database table.
• UPDATE: Changes or updates values in the table.
• DELETE: Removes records or rows from the table.
• SELECT: Retrieves data from the table or multiple tables.

3. Data control language (DCL)


Data control language (DCL) controls access to the data that users store within a database.
Essentially, this language controls the rights and permissions of the database system. It
allows users to grant or revoke privileges to the database.
Here's a list of DCL statements:
• GRANT: Gives a user access to the database.
• REVOKE: Removes a user's access to the database.

8
4. Transaction control language (TCL)
Transaction control language (TCL) manages the transactions within a database.
Transactions group a set of related tasks into a single, executable task. All the tasks must
succeed in order for the transaction to work. Here's a list of TCL statements:
• COMMIT: Carries out a transaction.
• ROLLBACK: Restores a transaction if any tasks fail to execute.

Table Description
Following are the tables along with constraints used in All in one travel booking database.

Products: Product_id uniquely identifies each product in the table.Product_name stores


the name of the product, limited to 40 characters.Description contains a description of
the product, limited to 40 characters.Price represents the price of the
product.Stock_Quantity stores the quantity of the product in stock, limited to 50
characters.Category_id refers to the category to which the product belongs.

Constraint: Primary Key: The primary key constraint is applied to the "Product_id"
column, ensuring that each product has a unique identifier within the table.
Foreign Key: The foreign key constraint is applied to the "Category_id" column,
referencing the "Category_id" column in the "categories" table. This constraint ensures that
the values in the "Category_id" column of the "Products" table must match the values in the
"Category_id" column of the "categories" table, maintaining the integrity of the relationship
between the two tables.

Categories: Category_id uniquely identifies each category in the table.Category_Name


stores the name of the category, limied to 40 characters

Constraint: Primary Key: The primary key constraint is applied to the "Category_id" column,

ensuring that each category has a unique identifier within the table.

9
Customers: Cid serves as the unique identifier for each customer in the table.Cname
stores the name of the customer, allowing up to 40 characters. Cage represents the age
of the customer.CMobile stores the mobile number of the customer, limited to 10
characters.CEmail contains the email address of the customer, allowing up to 300
characters.Caddress stores the address of the customer, allowing up to 300 characters.

Constraint: Primary Key: The primary key constraint is applied to the "Cid" column,
ensuring that each customer has a unique identifier within the table.

Orders: Order_id serves as the unique identifier for each order in the table.Customer_id
refers to the customer to whom the order belongs, linking to the "Cid" column in the
"Customers" table.Order_date represents the date when the order was
placed.Total_amount: integer - stores the total amount of the order.

Constraints: Primary Key the primary key constraint is applied to the "Order_id"
column, ensuring that each order has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "customer_id" column, referencing the "Cid"
column in the "Customers" table. This constraint ensures that the values in the
"customer_id" column of the "Orders" table must match the values in the "Cid"column
of the "Customers" table, maintaining the integrity of the relationship between the two
tables.

Transactions: Transaction_id serves as the unique identifier for each transaction in


the table.Order_id refers to the order associated with the transaction, linking to the
"Order_id" column in the "Orders" table.Payment_date represents the date when the
payment for the transaction was made.payment_method stores the payment method used
for the transaction, allowing up to 30 characters.Amount stores the amount of the
transaction.

Constraints: Primary Key the primary key constraint is applied to the "Transaction_id"
column, ensuring that each transaction has a unique identifier within the table.Foreign
Key the foreign key constraint is applied to the "Order_id" column, referencing the
"Order_id" column in the "Orders" table. This constraint ensures that the values in the
"Order_id" column of the "Transactions" table must match the values in the "Order_id"
column of the "Orders" table, maintaining the integrity of therelationship between the
two tables.
10
OrderItems Table: Order_id refers to the order to which the item belongs, linking to
the "Order_id" column in the "Orders" table.Product_id refers to the product associated
with the item, linking to the "Product_id" column in the "Products1" table.Quantity
represents the quantity of the product ordered.Price stores the price of the product.

Constraints: Foreign Key the foreign key constraint is applied to the "Order_id"
column, referencing the "Order_id" column in the "Orders" table. This constraintensures
that the values in the "Order_id" column of the "OrderItemsTable" table must match the
values in the "Order_id" column of the "Orders" table, maintaining the integrity of the
relationship between the two tables.Foreign Key the foreign key constraint is applied to
the "Product_id" column, referencing the "Product_id" column in the "Products1" table.
This constraint ensures that the values in the "Product_id" column of the
"OrderItemsTable" table must match the values in the "Product_id" column of the
"Products1" table, maintaining the integrity of the relationship between the two table.

Reviews: Review_id serves as the unique identifier for each review in the
table.Customer_id refers to the customer who wrote the review, linking to the "Cid"
column in the "Customers1" table.Product_id refers to the product for which thereview
was written, linking to the "Product_id" column in the "Products1" table.Rating
represents the rating given in the review. The CHECK constraint ensures that the rating
can only be 0, 1, 2, 3, 4, or 5.Comment stores the comment or review content, limited
to 20 characters.Review_date represents the date when the review was posted.

Constraints: Primary Key the primary key constraint is applied to the "review_id"
column, ensuring that each review has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "Customer_id" column, referencing the "Cid"
column in the "Customers1" table. This constraint ensures that the values in the
"Customer_id" column of the "Reviews" table must match the values in the "Cid"
column of the "Customers1" table, maintaining the integrity of the relationship between
the two tables.

11
Addressess: Customer_id refers to the customer to whom the address belongs, linking
to the "Cid" column in the "Customers1" table.C_Address stores the address of the
customer, limited to 50 characters.City stores the city associated with the address,
limited to 40 characters.

Constraints: Foreign Key the foreign key constraint is applied to the "Customer_id"
column, referencing the "Cid" column in the "Customers1" table. This constraintensures
that the values in the "Customer_id" column of the "Addressess" table must match the
values in the "Cid" column of the "Customers1" table, maintaining the integrity of the
relationship between the two tables.

Wishlist: Wishlist_id serves as the unique identifier for each wishlist in the
table.Customer_id refers to the customer who owns the wishlist, linking to the "Cid"
column in the "Customers1" table.Product_id refers to the product added to the wishlist,
linking to the "Product_id" column in the "Products1" table. Wishlist_Date represents
the date when the product was added to the wishlist.

Constraints: Primary Key the primary key constraint is applied to the "Wishlist_id"
column, ensuring that each wishlist has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "Customer_id" column, referencing the"Cid"
column in the "Customers1" table. This constraint ensures that the values in the
"Customer_id" column of the "Wishlist" table must match the values in the "Cid"
column of the "Customers1" table, maintaining the integrity of the relationship between
the two tables.Foreign Key the foreign key constraint is applied to the "Product_id"
column, referencing the "Product_id" column in the "Products1" table. This constraint
ensures that the values in the "Product_id" column of the "Wishlist" table must match
the values in the "Product_id" column of the "Products1" table, maintaining the integrity
of the relationship between the two tables.

12
Cart: Cart_item_id serves as the unique identifier for each item in the cart.Customer_id
refers to the customer who owns the cart, linking to the "Cid" column in the
"Customers1" table.Product_id refers to the product added to the cart, linking to the
"Product_id" column in the "Products1" table.Cart_date represents the date when the
product was added to the cart.Quantity stores the quantity of the productadded to the
cart.

Constraints: Primary Key the primary key constraint is applied to the "cart_item_id"
column, ensuring that each cart item has a unique identifier within the table.Foreign Key
the foreign key constraint is applied to the "Customer_id" column, referencing the"Cid"
column in the "Customers1" table. This constraint ensures that the values in the
"Customer_id" column of the "Cart" table must match the values in the "Cid" column
of the "Customers1" table, maintaining the integrity of the relationship between the
two tables.Foreign Key the foreign key constraint is applied to the "Product_id"column,
referencing the "Product_id" column in the "Products1" table. This constraint ensures
that the values in the "Product_id" column of the "Cart" table must match the values in
the "Product_id" column of the "Products1" table, maintaining the integrity

of the relationship between the two tables.

Promotions: Promotion_id serves as the unique identifier for each promotion in the
table.Promotion_Name stores the name or title of the promotion, allowing up to 50
characters.Promotion_Start_date represents the start date of the
promotion.Promotion_End_date represents the end date of the
promotion.discount_percentage stores the percentage of discount offered by the
promotion.

Constraints: Primary Key: The primary key constraint is applied to the "Promotion_id"
column, ensuring that each promotion has a unique identifier within the table.

13
Brands: Brand_id serves as the unique identifier for each brand in the table.
Brand_name stores the name of the brand, allowing up to 20 characters.

Constraints: Primary Key the primary key constraint is applied to the "Brand_id"
column, ensuring that each brand has a unique identifier within the table.

Discount: Discount_id serves as the unique identifier for each discount in the
table.Discount_code stores the discount code for each discount, limited to 20 characters.
The UNIQUE constraint ensures that each discount code is unique within the
table.Start_date represents the start date of the discount.End_date represents theend
date of the discount.Discount_percentage stores the percentage of the discount offered.
The decimal data type with precision 5 and scale 2 allows for values with upto 5 digits,
2 of which are reserved for decimal places.

Constraints: Primary Key the primary key constraint is applied to the "Discount_id"
column, ensuring that each discount has a unique identifier within the table.Unique
Constraint the unique constraint is applied to the "Discount_code" column, ensuring that
each discount code is unique within the table.

14
15
16
17
Relational Database Scheme
The relational database schema for Cricket World Cup database is as follows:

1. Products (Product_id,Product_Name,Description,Price,Stock_Quantity,Category_id)
2. Categories (Category_id,Category_Name)
3. Customers (Cid,CNmae,Cage,CMobile,CEmail,CAddress)
4. Orders (Order_id,Customer_id,Order_date,Total_amount)
5. Transactions (Transaction_id,Order_id,Payment_date, Payment_method,Amount)
6. Order Items Table (Order_id,Product_id,Quantity,Price)
7. Reviews (Review_id,Customer_id,Product_id,Rating,Comment,Review_date)
8. Addressess (Customer_id,C_Address,City)
9. Wishlist (Wishlist_id,Customer_id,Product_id,Wishlist_date)
10. Cart (Cart_item_id,Customer_id,Product_id,Cart_date,Quantity)
11. Brands (Brand_id,Brand_Name)
12. Discount (Discount_id,Discount_code,Start_date,End_date,Discount_percentage)

18
Relational Queries
/* create a table Products*/
Create table Products
(
Product_id int primary key,
product_name Varchar(40),
Description Varchar(40),
price money,
stock_quantity Varchar(50),
Category_id int Foreign key references categories(Category_id),
);
INSERT INTO Products(Product_id, Product_name, Description, Price, stock_quantity,
Category_id)
VALUES(1, 'iPhone 12', 'Apple smartphone', 999.99, 10, 1);
INSERT INTO Products (Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(2, 'Samsung Galaxy S21', 'Android smartphone', 899.99, 15, 1);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(3, 'Nike Air Max', 'Running shoes', 129.99, 20, 2);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(4, 'Adidas Ultraboost', 'Running shoes', 149.99, 30, 2);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(5, 'Instant Pot', 'Multi-cooker', 79.99, 5, 3);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(6, 'Cookware Set', 'Stainless steel pots and pans', 199.99, 8, 3);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(7, 'Harry Potter and the Sorcerer Stone', 'Fantasy novel', 12.99, 50, 4);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(8, 'The Great Gatsby', 'Classic novel', 9.99, 40, 4);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(9, 'Loreal Paris Mascara', 'Volumizing mascara', 8.99, 25, 5);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(10, 'NIVEA Men Shaving Cream', 'For sensitive skin', 4.99, 30, 5);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(11, 'Yoga Mat', 'Non-slip exercise mat', 19.99, 12, 6);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(12, 'Dumbbell Set', 'Weights for strength training', 49.99, 7, 6);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(13, 'LEGO Star Wars Set', 'Building blocks', 59.99, 18, 7);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(14, 'Board Game: Monopoly', 'Classic family game', 29.99, 25, 7);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(15, 'Car Jump Starter', 'Portable power bank', 79.99, 10, 8);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(16, 'Car Floor Mats', 'All-weather mats', 39.99, 15, 8);

19
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(17, 'Vitamin C Supplement', 'Immune support', 9.99, 40, 9);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(18, 'Fitness Tracker', 'Activity monitor', 49.99, 20, 9);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(19, 'Sofa', '3-seater couch', 599.99, 3, 10);
INSERT INTO Products(Product_id, Product_name, Description, Price, Stock_quantity,
Category_id)
VALUES(20, 'Dining Table', 'Wooden table with chairs', 399.99, 5, 10);
select *from Products;

Output:

Sno. Product Name Product Description Price Category Quantity


1 iPhone 12 Apple smartphone 999.99 10 1
2 Samsung Galaxy S21 Android smartphone 899.99 15 1
3 Nike Air Max Running shoes 129.99 20 2
4 Adidas Ultraboost Running shoes 149.99 30 2
5 Instant Pot Multi-cooker 79.99 5 3
Stainless steel pots and
6 Cookware Set pans 199.99 8 3
7 Harry Potter and the Sorcerer Stone Fantasy novel 12.99 50 4
8 The Great Gatsby Classic novel 9.99 40 4
9 Loreal Paris Mascara Volumizing mascara 8.99 25 5
10 NIVEA Men Shaving Cream For sensitive skin 4.99 30 5
11 Yoga Mat Non-slip exercise mat 19.99 12 6
Weights for strength
12 Dumbbell Set training 49.99 7 6
13 LEGO Star Wars Set Building blocks 59.99 18 7
14 Board Game: Monopoly Classic family game 29.99 25 7
15 Car Jump Starter Portable power bank 79.99 10 8
16 Car Floor Mats All-weather mats 39.99 15 8
17 Vitamin C Supplement Immune support 9.99 40 9
18 Fitness Tracker Activity monitor 49.99 20 9
19 Sofa 3-seater couch 599.99 3 10

20
/*create a table Categories*/
Create table Categories
(
Category_id int primary key,
Category_name Varchar(40),
);
INSERT INTO Categories (Category_id, Category_name)
VALUES(1, 'Electronics');
INSERT INTO Categories (Category_id, Category_name)
VALUES(2, 'Clothing');
INSERT INTO Categories (Category_id, Category_name)
VALUES(3, 'Home & Kitchen');
INSERT INTO Categories (Category_id, Category_name)
VALUES(4, 'Books');
INSERT INTO Categories (Category_id, Category_name)
VALUES(5, 'Beauty & Personal Care');
INSERT INTO Categories (Category_id, Category_name)
VALUES(6, 'Sports & Fitness');
INSERT INTO Categories (Category_id, Category_name)
VALUES(7, 'Toys & Games');
INSERT INTO Categories (Category_id, Category_name)
VALUES(8, 'Automotive');
INSERT INTO Categories (Category_id, Category_name)
VALUES(9, 'Health & Wellness');
INSERT INTO Categories (Category_id, Category_name)
VALUES(10, 'Furniture');

Output:

Category id Category Name


1 Electronics
2 Clothing
3 Home & Kitchen
4 Books
5 Beauty & Personal Care
6 Sports & Fitness
7 Toys & Games
8 Automotive
9 Health & Wellness
10 Furniture

21
/*create a table Customers*/

Create table Customers


(
Cid int primary key,
Cname Varchar(400),
Cage int,
CMobile Varchar(10),
CEmail Varchar(300),
Caddress Varchar(300),
);
drop table Customers
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(1, 'John Smith', 28, 1234567890, '[email protected]', '123 Main St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(2, 'Emily Johnson', 35, 9876543210, '[email protected]', '456 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(3, 'Michael Brown', 42, 5551234567, '[email protected]', '789 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(4, 'Emma Davis', 31, 7778889999, '[email protected]', '321 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(5, 'Daniel Wilson', 39, 4445556666, '[email protected]', '567 Cedar St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(6, 'Olivia Taylor', 24, 2223334444, '[email protected]', '890 Maple St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(7, 'William Johnson', 37, 9998887777, '[email protected]', '111 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(8, 'Sophia Anderson', 29, 6667778888, '[email protected]', '222 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(9, 'James Martinez', 33, 4445556666, '[email protected]', '333 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(10, 'Ava Smith', 26, 1234567890, '[email protected]', '444 Main St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(11, 'Logan Thompson', 35, 8889990000, '[email protected]', '555 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(12, 'Mia Davis', 30, 7778889999, '[email protected]', '666 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(13, 'Benjamin Thomas', 43, 2223334444, '[email protected]', '777 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(14, 'Charlotte Wilson', 27, 6667778888, '[email protected]', '888 Cedar St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(15, 'Henry Brown', 39, 4445556666, '[email protected]', '999 Maple St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(16, 'Evelyn Johnson', 32, 1112223333, '[email protected]', '1010 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(17, 'Jacob Smith', 29, 8889990000, '[email protected]', '1111 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(18, 'Abigail Davis', 36, 7778889999, '[email protected]', '1212 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(19, 'Liam Wilson', 25, 2223334444, '[email protected]', '1313 Cedar St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(20, 'Sofia Anderson', 34, 5556667777, '[email protected]', '1414 Maple St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(21, 'Harper Martinez', 28, 4445556666, '[email protected]', '1515 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(22, 'Ethan Taylor', 41, 1234567890, '[email protected]', '1616 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(23, 'Amelia Johnson', 33, 8889990000, '[email protected]', '1717 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(24, 'Logan Davis', 27, 7778889999, '[email protected]', '1818 Cedar St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(25, 'Oliver Thomas', 38, 2223334444, '[email protected]', '1919 Maple St');
22
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(26, 'Mia Wilson', 30, 6667778888, '[email protected]', '2020 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(27, 'Lucas Brown', 36, 5556667777, '[email protected]', '2121 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(28, 'Evelyn Johnson', 29, 4445556666, '[email protected]', '2222 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(29, 'Jackson Smith', 32, 1234567890, '[email protected]', '2323 Cedar St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(30, 'Ava Davis', 37, 8889990000, '[email protected]', '2424 Maple St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(31, 'Aiden Anderson', 31, 7778889999, '[email protected]', '2525 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(32, 'Ella Martinez', 24, 2223334444, '[email protected]', '2626 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(33, 'Carter Wilson', 39, 6667778888, '[email protected]', '2727 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(34, 'Scarlett Brown', 28, 5556667777, '[email protected]', '2828 Cedar St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(35, 'Sebastian Thomas', 35, 4445556666, '[email protected]', '2929 Maple St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(36, 'Luna Johnson', 26, 1234567890, '[email protected]', '3030 Oak St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(37, 'Grayson Davis', 40, 8889990000, '[email protected]', '3131 Pine St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(38, 'Penelope Wilson', 27, 7778889999, '[email protected]', '3232 Elm St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(39, 'Mateo Anderson', 33, 2223334444, '[email protected]', '3333 Cedar St');
INSERT INTO Customers(Cid, Cname, Cage, CMobile, CEmail, Caddress) VALUES
(40, 'Victoria Martinez', 35, 5556667777, '[email protected]',
'3434 Maple St');

23
Output

Sno. CName Cage CMobile CEmail CAddress


1 John Smith 28 1234567890 [email protected] 123 Main St
2 Emily Johnson 35 9876543210 [email protected] 456 Elm St
3 Michael Brown 42 5551234567 [email protected] 789 Oak St
4 Emma Davis 31 7778889999 [email protected] 321 Pine St
5 Daniel Wilson 39 4445556666 [email protected] 567 Cedar St
6 Olivia Taylor 24 2223334444 [email protected] 890 Maple St
7 William Johnson 37 9998887777 [email protected] 111 Oak St
8 Sophia Anderson 29 6667778888 [email protected] 222 Pine St
9 James Martinez 33 4445556666 [email protected] 333 Elm St
10 Ava Smith 26 1234567890 [email protected] 444 Main St
11 Logan Thompson 35 8889990000 [email protected] 555 Oak St
12 Mia Davis 30 7778889999 [email protected] 666 Pine St
13 Benjamin Thomas 43 2223334444 [email protected] 777 Elm St
14 Charlotte Wilson 27 6667778888 [email protected] 888 Cedar St
15 Henry Brown 39 4445556666 [email protected] 999 Maple St
16 Evelyn Johnson 32 1112223333 [email protected] 1010 Oak St
17 Jacob Smith 29 8889990000 [email protected] 1111 Pine St
18 Abigail Davis 36 7778889999 [email protected] 1212 Elm St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
20 Sofia Anderson 34 5556667777 [email protected] 1414 Maple St
21 Harper Martinez 28 4445556666 [email protected] 1515 Oak St
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St
23 Amelia Johnson 33 8889990000 [email protected] 1717 Elm St
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St
25 Oliver Thomas 38 2223334444 [email protected] 1919 Maple St
26 Mia Wilson 30 6667778888 [email protected] 2020 Oak St
27 Lucas Brown 36 5556667777 [email protected] 2121 Pine St
28 Evelyn Johnson 29 4445556666 [email protected] 2222 Elm St
29 Jackson Smith 32 1234567890 [email protected] 2323 Cedar St
30 Ava Davis 37 8889990000 [email protected] 2424 Maple St
31 Aiden Anderson 31 7778889999 [email protected] 2525 Oak St
32 Ella Martinez 24 2223334444 [email protected] 2626 Pine St
33 Carter Wilson 39 6667778888 [email protected] 2727 Elm St
34 Scarlett Brown 28 5556667777 [email protected] 2828 Cedar St
35 Sebastian Thomas 35 4445556666 [email protected] 2929 Maple St
36 Luna Johnson 26 1234567890 [email protected] 3030 Oak St
37 Grayson Davis 40 8889990000 [email protected] 3131 Pine St
38 Penelope Wilson 27 7778889999 [email protected] 3232 Elm St
39 Mateo Anderson 33 2223334444 [email protected] 3333 Cedar St
40 Victoria Martinez 35 5556667777 [email protected] 3434 Maple St

24
/*create a table Transactions*/
Create Table Transactions2
(
Transaction_id int Primary Key,
Order_id int Foreign Key References Orders2(Order_id),
Payment_date date,
payment_method varchar(30),
Amount int,
);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(1, 1, '2023-05-01', 'Credit Card', 50);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(2, 12, '2023-05-02', 'PayPal', 75);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(3, 3, '2023-05-03', 'Credit Card', 100);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(4, 14, '2023-05-04', 'Google Pay', 20);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(5, 15, '2023-05-05', 'Credit Card', 150);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(6, 16, '2023-05-06', 'Credit Card', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(7, 17, '2023-05-07', 'PayPal', 90);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(8, 18, '2023-05-08', 'Credit Card', 80);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(9, 9, '2023-05-09', 'Google Pay', 40);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(10, 10, '2023-05-10', 'Credit Card', 120);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(11, 10, '2023-05-11', 'PayPal', 60);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(12, 12, '2023-05-12', 'Credit Card', 30);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(13, 13, '2023-05-13', 'Google Pay', 110);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(14, 14, '2023-05-14', 'Credit Card', 65);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(15, 15, '2023-05-15', 'Credit Card', 95);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(16, 16, '2023-05-16', 'PayPal', 55);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(17, 19, '2023-05-17', 'Credit Card', 85);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(18, 18, '2023-05-18', 'Google Pay', 25);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(9, 1019, '2023-05-19', 'Credit Card', 135);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(20, 21, '2023-05-20', 'PayPal', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(21, 20, '2023-05-21', 'Credit Card', 120);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(22, 25, '2023-05-22', 'Google Pay', 60);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(23, 22, '2023-05-23', 'Credit Card', 40);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(24, 23, '2023-05-24', 'Credit Card', 150);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(25, 24, '2023-05-25', 'PayPal', 90);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(26, 22, '2023-05-26', 'Credit Card', 80);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(27, 28, '2023-05-27', 'Google Pay', 20);
25
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(28, 24, '2023-05-28', 'Credit Card', 100);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(29, 19, '2023-05-29', 'Credit Card', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(30, 10, '2023-05-30', 'PayPal', 110);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(31, 19, '2023-05-31', 'Credit Card', 65);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(32, 12, '2023-06-01', 'Google Pay', 95);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(33, 13, '2023-06-02', 'Credit Card', 55);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(34, 14, '2023-06-03', 'Credit Card', 85);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(35, 15, '2023-06-04', 'PayPal', 25);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(36, 16, '2023-06-05', 'Credit Card', 135);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(37, 19, '2023-06-06', 'Google Pay', 70);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(38, 20, '2023-06-07', 'Credit Card', 120);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(39, 21, '2023-06-08', 'Credit Card', 60);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(40, 29, '2023-06-09', 'PayPal', 40);
INSERT INTO Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
VALUES(41, 18, '2023-06-09', 'Paytm', 90);
Insert Into Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
Values(42, 19, '2023-05-09', 'Debit Card', 100);
Insert Into Transactions2 (Transaction_id, Order_id, Payment_date, Payment_method, Amount)
Values(43, 20, '2023-08-08', 'Debit Card', 100);

26
Output

Transac_id Order_id Pay_Date Pay_Method Amount


1 1 2023-05-01 Credit Card 50
2 12 2023-05-02 PayPal 75
3 3 2023-05-03 Credit Card 100
4 14 2023-05-04 Google Pay 20
6 16 2023-05-06 Credit Card 70
7 17 2023-05-07 PayPal 90
8 18 2023-05-08 Credit Card 80
9 9 2023-05-09 Google Pay 40
10 10 2023-05-10 Credit Card 120
11 10 2023-05-11 PayPal 60
12 12 2023-05-12 Credit Card 30
13 13 2023-05-13 Google Pay 110
14 14 2023-05-14 Credit Card 65
16 16 2023-05-16 PayPal 55
17 19 2023-05-17 Credit Card 85
18 18 2023-05-18 Google Pay 25
20 21 2023-05-20 PayPal 70
21 20 2023-05-21 Credit Card 120
22 25 2023-05-22 Google Pay 60
23 22 2023-05-23 Credit Card 40
24 23 2023-05-24 Credit Card 150
25 24 2023-05-25 PayPal 90
26 22 2023-05-26 Credit Card 80
27 28 2023-05-27 Google Pay 20
28 24 2023-05-28 Credit Card 100
29 19 2023-05-29 Credit Card 70
30 10 2023-05-30 PayPal 110
31 19 2023-05-31 Credit Card 65
32 12 2023-06-01 Google Pay 95
33 13 2023-06-02 Credit Card 55
34 14 2023-06-03 Credit Card 85
36 16 2023-06-05 Credit Card 135
37 19 2023-06-06 Google Pay 70
38 20 2023-06-07 Credit Card 120
39 21 2023-06-08 Credit Card 60
40 29 2023-06-09 PayPal 40
41 18 2023-06-09 Paytm 90
42 19 2023-05-09 Debit Card 100
43 20 2023-08-08 Debit Card 100

27
/*create a table Orders2 */

create table Orders2


(
Order_id int Primary Key ,
Customer_id int Foreign Key References Customers(Cid),
Order_date date,
total_amount decimal(10,5),
);

INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)


VALUES(1, 29, '2023-05-01', 250);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(2, 29, '2023-05-03', 150);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(3, 29, '2023-05-05', 80);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(4, 29, '2023-05-08', 350);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(5, 29, '2023-05-10', 200);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(6, 30, '2023-03-11', 1900);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(7, 17, '2023-01-07', 70);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(8, 18, '2023-01-08', 55);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(9, 9, '2023-01-09', 65);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(10, 11, '2023-01-10', 95);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(11, 11, '2023-01-11', 120);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(12, 12, '2023-01-12', 85);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(13, 13, '2023-01-13', 50);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(14, 24, '2023-01-14', 75);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(16, 26, '2023-01-16', 90);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(17, 27, '2023-01-17', 100);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(18, 8, '2023-01-18', 80);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(19, 19, '2023-01-19', 70);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(20, 12, '2023-01-20', 55);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(21, 21, '2023-01-21', 65);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(22, 22, '2023-01-22', 95);

28
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(23, 23, '2023-01-23', 120);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(24, 24, '2023-01-24', 85);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(25, 25, '2023-01-25', 50);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(26, 16, '2023-01-26', 75);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(27, 27, '2023-01-27', 60);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(28, 28, '2023-01-28', 90);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(29, 29, '2023-01-29', 100);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(30, 30, '2023-01-30', 80);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(31, 31, '2023-01-31', 70);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(32, 13, '2023-02-01', 55);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(33, 23, '2023-02-02', 65);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(34, 34, '2023-02-03', 95);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(35, 35, '2023-02-04', 120);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(36, 13, '2023-02-05', 85);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(37, 17, '2023-02-06', 50);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(38, 8, '2023-02-07', 75);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(39, 9, '2023-02-08', 60);
INSERT INTO Orders2 (Order_id, customer_id, Order_date, total_amount)
VALUES(40, 40, ‘2023-02-09’,90);

29
Output

Order_id Cid Order_date amount


1 29 2023-05-01 250
2 29 2023-05-03 150
3 29 2023-05-05 80
4 29 2023-05-08 350
5 29 2023-05-10 200
6 30 2023-03-11 1900
7 17 2023-01-07 70
8 18 2023-01-08 55
9 9 2023-01-09 65
10 11 2023-01-10 95
11 11 2023-01-11 120
12 12 2023-01-12 85
13 13 2023-01-13 50
14 24 2023-01-14 75
16 26 2023-01-16 90
17 27 2023-01-17 100
18 8 2023-01-18 80
19 19 2023-01-19 70
20 12 2023-01-20 55
21 21 2023-01-21 65
22 22 2023-01-22 95
23 23 2023-01-23 120
24 24 2023-01-24 85
25 25 2023-01-25 50
26 16 2023-01-26 75
27 27 2023-01-27 60
28 28 2023-01-28 90
29 29 2023-01-29 100
30 30 2023-01-30 80
31 31 2023-01-31 70
32 13 2023-02-01 55
33 23 2023-02-02 65
34 34 2023-02-03 95
35 35 2023-02-04 120
36 13 2023-02-05 85
37 17 2023-02-06 50
38 8 2023-02-07 75
39 9 2023-02-08 60
40 40 2023-02-09 90

30
/* create a table Order Items Table2*/

Create table OrderItemsTable2


(
Order_id int Foreign Key References Orders2(Order_id),
Product_id int Foreign Key References Products(Product_id),
Quantity int,
Price money,
);
INSERT INTO OrderItemsT ab le2 (Order_id, Product_id, Quantity, Price)
VALUES (1, 4, 2, 25.99) ;
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES (2, 4, 1, 14.99);
INSERT INTO OrderItemsT able2 (Order_id, Product_id, Quantity, Price)
VALUES (4, 4, 3, 9.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES (3, 4, 1, 19.99);
INSERT INTO OrderItemsT able2 (Order_id, Product_id, Quantity, Price)
VALUES (5, 4, 2, 7.99);
INSERT INTO OrderItemsTab le2 (Order_id, Product_id, Quantity, Price)
VALUES(11, 21, 2, 25.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(12, 22, 1, 12.50);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(14, 23, 3, 9.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(15, 24, 2, 15.75);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(18, 15, 1, 8.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(19, 11, 2, 25.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(24, 14, 1, 9.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(25, 16, 2, 8.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(28, 18, 3, 12.50);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(29, 19, 1, 15.75);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(16, 11, 1, 25.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(10, 23, 2, 9.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(11, 20, 2, 12.50);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(12, 21, 1, 15.75);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(18, 25, 1, 8.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(19, 26, 1, 25.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(20, 28, 1, 9.99);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(21, 9, 2, 15.75);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(29, 18, 2, 12.50);
INSERT INTO OrderItemsTable2 (Order_id, Product_id, Quantity, Price)
VALUES(19, 25, 1, 8.99);

31
Output

Order_id P_id Quantity Price


1 4 2 25.99
2 4 1 14.99
4 4 3 9.99
3 4 1 19.99
5 4 2 7.99
18 15 1 8.99
19 11 2 25.99
24 14 1 9.99
25 16 2 8.99
28 18 3 12.5
29 19 1 15.75
16 11 1 25.99
11 20 2 12.5
21 9 2 15.75
29 18 2 12.5

32
/* create a table Reviews2*/
Create Table Reviews2
(
review_id int Primary Key,
Customer_id int Foreign Key References Customers(Cid),
Product_id int Foreign Key References Products(Product_id),
rating int check(rating = 0 or rating = 1 or rating = 2 or rating = 3 or rating = 4 or
rating = 5),
Comment Varchar(20),
Review_date date,
);
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (1, 10, 4, 4, 'Great product!', '2023-05-01');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (2, 2, 4, 5, 'Excellent service!', '2023-05-03');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (3, 1, 4, 3, 'Average quality.', '2023-05-05');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (4, 35, 4, 2, 'Not satisfied.', '2023-05-07');
INSERT INTO Reviews2 (review_id, Customer_id, Product_id, rating, Comment, Review_date)
VALUES (5, 19, 4, 5, 'Highly recommended!', '2023-05-10');

Output

Review_id C_id Pid Rating Comment Review_Date


1 10 4 4 Great product! 2023-05-01
2 2 4 5 Excellent service! 2023-05-03
3 1 4 3 Average quality. 2023-05-05
4 35 4 2 Not satisfied. 2023-05-07
5 19 4 5 Highly recommended! 2023-05-10

33
/*create a table Addressess2 */
Create Table Addressess2
(
Customer_id int Foreign Key References Customers(Cid),
C_Address Varchar(50),
City Varchar(40)
);
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (1, '123 Main St', 'New York');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (10, '456 Elm St', 'Los Angeles');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (13, '789 Oak St', 'Chicago');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (19, '321 Pine St', 'San Francisco');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES (30, '654 Cedar St', 'Miami');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(14, '321 Cedar Ln', 'Miami');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(15, '876 Walnut St', 'Boston');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(16, '543 Spruce Dr', 'Seattle');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(17, '210 Birch Ave', 'Denver');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(18, '135 Oak St', 'Dallas');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(21, '468 Pine Rd', 'San Diego');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(28, '975 Cedar Ln', 'Atlanta');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(29, '246 Elm St', 'Phoenix');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(23, '864 Maple Ave', 'Philadelphia');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(25, '369 Walnut St', 'Las Vegas');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(27, '582 Spruce Dr', 'Austin');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(30, '123 Birch Ave', 'Nashville');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(31, '456 Oak St', 'Portland');
INSERT INTO Addressess2 (Customer_id, C_Address, City)
VALUES(32,’789 Pine Rd’,’Charlotte’);

34
Output

C_id C_Address City


1 123 Main St New York
10 456 Elm St Los Angeles
13 789 Oak St Chicago
19 321 Pine St San Francisco
30 654 Cedar St Miami
14 321 Cedar Ln Miami
15 876 Walnut St Boston
16 543 Spruce Dr Seattle
17 210 Birch Ave Denver
18 135 Oak St Dallas
21 468 Pine Rd San Diego
28 975 Cedar Ln Atlanta
29 246 Elm St Phoenix
23 864 Maple Ave Philadelphia
25 369 Walnut St Las Vegas
27 582 Spruce Dr Austin
30 123 Birch Ave Nashville
31 456 Oak St Portland
38 789 Pine Rd Charlotte
39 987 Cedar Ln San Antonio

35
/*create a table Wishlist2 */

Create Table Wishlist2


(
Wishlist_id int Primary Key,
Customer_id int Foreign Key References Customers(Cid),
Product_id int Foreign Key References Products(Product_id),
Wishlist_Date date,
);

INSERT INTO Wishlist2 (Wishlist_id, Customer_id, Product_id, Wishlist_Date)


VALUES (1, 1, 1, '2023-05-01');
INSERT INTO Wishlist2 (Wishlist_id, Customer_id, Product_id, Wishlist_Date)
VALUES (2, 2, 2, '2023-05-03');
INSERT INTO Wishlist2 (Wishlist_id, Customer_id, Product_id, Wishlist_Date)
VALUES (3, 10, 4, '2023-05-05');
INSERT INTO Wishlist2 (Wishlist_id, Customer_id, Product_id, Wishlist_Date)
VALUES (4, 19, 4, '2023-05-07');
INSERT INTO Wishlist2 (Wishlist_id, Customer_id, Product_id, Wishlist_Date)
VALUES (5, 30, 5, ’2023-05-10’);

Output

Wid Cid Pid W_Date


1 1 1 2023-05-01
2 2 2 2023-05-03
3 10 4 2023-05-05
4 19 4 2023-05-07
5 30 5 2023-05-10

36
/*create a table Cart2 */

Create Table Cart2


(
cart_item_id int Primary Key,
Customer_id int Foreign Key References Customers(Cid),
Product_id int Foreign Key References Products(Product_id),
Cart_date date,
quantity int,
);

INSERT INTO Cart2 (cart_item_id, Customer_id, Product_id, Cart_date, quantity)


VALUES (1, 11, 2, '2023-05-01', 2);
INSERT INTO Cart2 (cart_item_id, Customer_id, Product_id, Cart_date, quantity)
VALUES (2, 19, 4, '2023-05-03', 1);
INSERT INTO Cart2 (cart_item_id, Customer_id, Product_id, Cart_date, quantity)
VALUES (3, 30, 3, '2023-05-05', 3);
INSERT INTO Cart2 (cart_item_id, Customer_id, Product_id, Cart_date, quantity)
VALUES (4, 13, 4, '2023-05-07', 1);
INSERT INTO Cart2 (cart_item_id, Customer_id, Product_id, Cart_date, quantity)
VALUES (5, 12, 5, '2023-05-10', 2);

Output

Cart_id Cid P_id Cart_Date Quantity


1 11 2 2023-05-01 2
2 19 4 2023-05-03 1
3 30 3 2023-05-05 3
4 13 4 2023-05-07 1
5 12 5 2023-05-10 2

37
/* Create table Promotions2 */

Create Table Promotions1


(
Promotion_id int Primary Key,
Promotion_Name Varchar(50),
Promotion_Start_date date,
Promotion_End_date date,
discount_percentage int,
);

INSERT INTO Promotions1 (Promotion_id, Promotion_Name, Promotion_Start_date,


Promotion_End_date, discount_percentage)
VALUES (1, 'Summer Sale', '2023-06-01', '2023-06-30', 10);
INSERT INTO Promotions1 (Promotion_id, Promotion_Name, Promotion_Start_date,
Promotion_End_date, discount_percentage)
VALUES (2, 'Flash Deal', '2023-07-15', '2023-07-16', 20);
INSERT INTO Promotions1 (Promotion_id, Promotion_Name, Promotion_Start_date,
Promotion_End_date, discount_percentage)
VALUES (3, 'Holiday Special', '2023-12-01', '2024-01-01', 15);
INSERT INTO Promotions1 (Promotion_id, Promotion_Name, Promotion_Start_date,
Promotion_End_date, discount_percentage)
VALUES (4, 'Back to School', '2023-08-15', '2023-09-15', 12);
INSERT INTO Promotions1 (Promotion_id, Promotion_Name, Promotion_Start_date,
Promotion_End_date, discount_percentage)
VALUES (5, 'Black Friday', '2023-11-24', '2023-11-24', 25);

Output

Pr_id Pr_name Pr_start_Date Pr_End_Date Discount


1 Summer Sale 2023-06-01 2023-06-30 10
2 Flash Deal 2023-07-15 2023-07-16 20
3 Holiday Special 2023-12-01 2024-01-01 15
4 Back to School 2023-08-15 2023-09-15 12
5 Black Friday 2023-11-24 2023-11-24 25

38
/*create a table Brands2 */

Create Table Brands


(
Brand_id int Primary key,
Brand_name Varchar(20),
);

INSERT INTO Brands (Brand_id, Brand_name)


VALUES(1, 'Nike');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(2, 'Adidas');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(3, 'Puma');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(4, 'Reebok');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(5, 'Under Armour');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(6, 'New Balance');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(7, 'Vans');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(8, 'Converse');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(9, 'Fila');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(10, 'Skechers');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(11, 'Lacoste');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(12, 'Timberland');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(13, 'ASICS');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(14, 'Crocs');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(15, 'Balenciaga');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(16, 'Gucci');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(17, 'Prada');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(18, 'Versace');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(19, 'Calvin Klein');
INSERT INTO Brands (Brand_id, Brand_name)
VALUES(20, 'Tommy Hilfiger');

39
Output

Brand_id Brand_Name
1 Nike
2 Adidas
3 Puma
4 Reebok
5 Under Armour
6 New Balance
7 Vans
8 Converse
9 Fila
10 Skechers
11 Lacoste
12 Timberland
13 ASICS
14 Crocs
15 Balenciaga
16 Gucci
17 Prada
18 Versace
19 Calvin Klein
20 Tommy Hilfiger

40
SQL Queries

Query1: Give complete information for products with category name

SELECT
p.*,c.Category_name
FROM Products p
JOIN Categories c
ON p.Category_id = c.Category_id;

output:

P_id P_Name Description Price Quantity Cat_id Cate_Name


1 iPhone 12 Apple smartphone 999.99 10 1 Electronics
2 Samsung Galaxy S21 Android smartphone 899.99 15 1 Electronics
3 Nike Air Max Running shoes 129.99 20 2 Clothing
4 Adidas Ultraboost Running shoes 149.99 30 2 Clothing
5 Instant Pot Multi-cooker 79.99 5 3 Home & Kitchen
Stainless steel pots
6 Cookware Set and pans 199.99 8 3 Home & Kitchen
Harry Potter and the
7 Sorcerer Stone Fantasy novel 12.99 50 4 Books
8 The Great Gatsby Classic novel 9.99 40 4 Books
9 Loreal Paris Mascara Volumizing mascara 8.99 25 5 Beauty & Personal Care
NIVEA Men Shaving
10 Cream For sensitive skin 4.99 30 5 Beauty & Personal Care
Non-slip exercise
11 Yoga Mat mat 19.99 12 6 Sports & Fitness
Weights for strength
12 Dumbbell Set training 49.99 7 6 Sports & Fitness
13 LEGO Star Wars Set Building blocks 59.99 18 7 Toys & Games
Board Game:
14 Monopoly Classic family game 29.99 25 7 Toys & Games
Portable power
15 Car Jump Starter bank 79.99 10 8 Automotive
16 Car Floor Mats All-weather mats 39.99 15 8 Automotive
Vitamin C
17 Supplement Immune support 9.99 40 9 Health & Wellness
18 Fitness Tracker Activity monitor 49.99 20 9 Health & Wellness
19 Sofa 3-seater couch 599.99 3 10 Furniture
Wooden table with
20 Dining Table chairs 399.99 5 10 Furniture

41
Query2: Give complete information of Customers with Order_id , Payment_Date and Order_Amount

SELECT c.*, t.Order_id,t.Payment_date,t.Amount


FROM Customers c
JOIN Transactions2 t ON c.Cid = t.Order_id;

Output:

Cid CName Cage Cmobile CEmail Address Oid PayDate Amo


1234567890 123 Main 23-05-01
1 JohnSmith 28 [email protected] St 1 50
7778889999 666 Pine 23-05-02
12 Mia Davis 30 [email protected] St 12 75
Michael 5551234567 789 Oak 23-05-03
3 Brown 42 [email protected] St 3 100
Charlotte 6667778888 [email protected] 888 Cedar 23-05-04
14 Wilson 27 m St 14 20
Evelyn 1112223333 1010 Oak 23-05-06
16 Johnson 32 [email protected] St 16 70
Jacob 8889990000 1111 Pine 23-05-07
17 Smith 29 [email protected] St 17 90
Abigail 7778889999 1212 Elm 23-05-08
18 Davis 36 [email protected] St 18 80
James 4445556666 [email protected] 333 Elm 23-05-09
9 Martinez 33 m St 9 40
1234567890 444 Main 23-05-10
10 Ava Smith 26 [email protected] St 10 120
1234567890 444 Main 23-05-11
10 Ava Smith 26 [email protected] St 10 60
7778889999 666 Pine 23-05-12
12 Mia Davis 30 [email protected] St 12 30
Benjamin 2223334444 [email protected] 777 Elm 23-05-13
13 Thomas 43 om St 13 110
Charlotte 6667778888 [email protected] 888 Cedar 23-05-14
14 Wilson 27 m St 14 65
Evelyn 1112223333 1010 Oak 23-05-16
16 Johnson 32 [email protected] St 16 55
Liam 2223334444 1313 23-05-17
19 Wilson 25 [email protected] Cedar St 19 85
Abigail 7778889999 1212 Elm 23-05-18
18 Davis 36 [email protected] St 18 25
Harper 4445556666 [email protected] 1515 Oak 23-05-20
21 Martinez 28 m St 21 70
Sofia 5556667777 1414 23-05-21
20 Anderson 34 [email protected] Maple St 20 120
Oliver 2223334444 1919 23-05-22
25 Thomas 38 [email protected] Maple St 25 60
Ethan 1234567890 1616 Pine 23-05-23
22 Taylor 41 [email protected] St 22 40
Amelia 8889990000 [email protected] 1717 Elm 23-05-24
23 Johnson 33 m St 23 150
42
Cid CName Cage CMobile CEmail Address Oid PayDate Amo
Logan 7778889999 1818 23-05-25
24 Davis 27 [email protected] Cedar St 24 90
Ethan 1234567890 1616 Pine 23-05-26
22 Taylor 41 [email protected] St 22 80
Evelyn 4445556666 2222 Elm 23-05-27
28 Johnson 29 [email protected] St 28 20
Logan 7778889999 1818 23-05-28
24 Davis 27 [email protected] Cedar St 24 100
Liam 2223334444 1313 23-05-29
19 Wilson 25 [email protected] Cedar St 19 70
1234567890 444 Main 23-05-30
10 Ava Smith 26 [email protected] St 10 110
Liam 2223334444 1313 23-05-31
19 Wilson 25 [email protected] Cedar St 19 65
7778889999 666 Pine 23-06-01
12 Mia Davis 30 [email protected] St 12 95
Benjamin 2223334444 [email protected] 777 Elm 23-06-02
13 Thomas 43 om St 13 55
Charlotte 6667778888 [email protected] 888 Cedar 23-06-03
14 Wilson 27 m St 14 85
Evelyn 1112223333 1010 Oak 23-06-05
16 Johnson 32 [email protected] St 16 135
Liam 2223334444 1313 23-06-06
19 Wilson 25 [email protected] Cedar St 19 70
Sofia 5556667777 1414 23-06-07
20 Anderson 34 [email protected] Maple St 20 120
Harper 4445556666 [email protected] 1515 Oak 23-06-08
21 Martinez 28 m St 21 60
Jackson 1234567890 2323 23-06-09
29 Smith 32 [email protected] Cedar St 29 40
Abigail 7778889999 1212 Elm 23-06-09
18 Davis 36 [email protected] St 18 90
Liam 2223334444 1313 23-05-09
19 Wilson 25 [email protected] Cedar St 19 100
Sofia 5556667777 1414 23-08-08
20 Anderson 34 [email protected] Maple St 20 100

43
Query3: Find the name of the customer with total amount he had payed

SELECT c.Cname, SUM(t.Amount) AS


TotalAmount FROM Customers c
JOIN Transactions2 t
ON c.Cid = t.Order_id
GROUP BY c.Cname;

Output

CName TotalAmount
Abigail Davis 195
Amelia Johnson 150
Ava Smith 290
Benjamin Thomas 165
Charlotte Wilson 170
Ethan Taylor 120
Evelyn Johnson 280
Harper Martinez 130
Jackson Smith 40
Jacob Smith 90
James Martinez 40
John Smith 50
Liam Wilson 390
Logan Davis 190
Mia Davis 200
Michael Brown 100
Oliver Thomas 60
Sofia Anderson 340
Abigail Davis 195
Amelia Johnson 150
Ava Smith 290
Benjamin Thomas 165
Charlotte Wilson 170
Ethan Taylor 120

44
Query4: Find the id of the customer along with total amount he had payed

SELECT c.Cid , SUM(t.Amount) AS


TotalAmount FROM Customers c
JOIN Transactions2 t
ON c.Cid = t.Order_id
GROUP BY c.Cid;

Output:

Cid TotalAmount
1 50
3 100
9 40
10 290
12 200
13 165
14 170
16 260
17 90
18 195
19 390
20 340
21 130
22 120
23 150
24 190
25 60
28 20
29 40

45
Query 5: Find the details of Products which are having price greater than 100

SELECT * FROM
Products
WHERE Price > 100;

Output

Pid Pname Description Price Quantity Category_id


1 iPhone 12 Apple smartphone 999.99 10 1
2 Samsung Galaxy S21 Android smartphone 899.99 15 1
3 Nike Air Max Running shoes 129.99 20 2
4 Adidas Ultraboost Running shoes 149.99 30 2
6 Cookware Set Stainless steel pots and pans 199.99 8 3
19 Sofa 3-seater couch 599.99 3 10
20 Dining Table Wooden table with chairs 399.99 5 10

Query 6: Find the details of customers whose address is “321 Pine st”

select * from Customers


where Caddress = '321 Pine st';

output

Cid CName Cage CMobile CEmail CAddress


4 Emma Davis 31 7778889999 [email protected] 321 Pine St

Query 7: Find the customer who has order any items

select * from Customers as C


where Cid in (select Customer_id from Orders2 as O where C.Cid = O.Customer_id)

output

Cid CName Cage CMobile CEmail CAddress


8 Sophia Anderson 29 6667778888 [email protected] 222 Pine St
9 James Martinez 33 4445556666 [email protected] 333 Elm St
11 Logan Thompson 35 8889990000 [email protected] 555 Oak St
12 Mia Davis 30 7778889999 [email protected] 666 Pine St
13 Benjamin Thomas 43 2223334444 [email protected] 777 Elm St
16 Evelyn Johnson 32 1112223333 [email protected] 1010 Oak St
17 Jacob Smith 29 8889990000 [email protected] 1111 Pine St
18 Abigail Davis 36 7778889999 [email protected] 1212 Elm St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
21 Harper Martinez 28 4445556666 [email protected] 1515 Oak St
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St
23 Amelia Johnson 33 8889990000 [email protected] 1717 Elm St
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St
25 Oliver Thomas 38 2223334444 [email protected] 1919 Maple St
26 Mia Wilson 30 6667778888 [email protected] 2020 Oak St
27 Lucas Brown 36 5556667777 [email protected] 2121 Pine St
46
Cid CName Cage CMobile CEmail CAddress
28 Evelyn Johnson 29 4445556666 [email protected] 2222 Elm St
29 Jackson Smith 32 1234567890 [email protected] 2323 Cedar St
30 Ava Davis 37 8889990000 [email protected] 2424 Maple St
31 Aiden Anderson 31 7778889999 [email protected] 2525 Oak St
34 Scarlett Brown 28 5556667777 [email protected] 2828 Cedar St
35 Sebastian Thomas 35 4445556666 [email protected] 2929 Maple St
40 Victoria Martinez 35 5556667777 [email protected] 3434 Maple St

Query 8: Find the id of Customer with the number of times customer ordered who has ordered more than one
Time

select customer_id, count(Order_id) as Number_of_items_Ordered


from Orders2
Group by customer_id
HAVING count(Order_id) > 1 ;

Output

Cid Number_of_times_Ordered
8 2
9 2
11 2
12 2
13 3
17 2
23 2
24 2
27 2
29 6
30 2

47
48
Query 9: Find the customer id and order date of the customers

select C.Cid , O.Order_date from Customers as C join Orders2 as O


on C.Cid = O.customer_id

Output

Cid Order_Date
29 2023-05-01
29 2023-05-03
29 2023-05-05
29 2023-05-08
29 2023-05-10
30 2023-03-11
17 2023-01-07
18 2023-01-08
9 2023-01-09
11 2023-01-10
11 2023-01-11
12 2023-01-12
13 2023-01-13
24 2023-01-25
26 2023-01-26
27 2023-01-27
8 2023-01-28
19 2023-01-29
12 2023-01-30
21 2023-01-31
22 2023-02-01
23 2023-02-02
24 2023-02-03
25 2023-02-04
16 2023-02-05
27 2023-02-06
28 2023-02-07
29 2023-02-08
30 2023-02-09
31 2023-01-25
13 2023-01-26
23 2023-01-27
34 2023-01-28
35 2023-01-29
13 2023-01-30
23 2023-01-31
34 2023-02-01
35 2023-02-02
13 2023-02-03
17 2023-02-04
8 2023-02-05
9 2023-02-06
40 2023-02-07
49
Query 10: Find Cid and CMobile from Customers who ordered any item

select Cid,CMobile From Customers


where Cid in (select customer_id from Orders2)

Output

Cid CMobile
8 6667778888
9 4445556666
11 8889990000
12 7778889999
13 2223334444
16 1112223333
17 8889990000
18 7778889999
19 2223334444
21 4445556666
22 1234567890
23 8889990000
24 7778889999
25 2223334444
26 6667778888
27 5556667777
28 4445556666
29 1234567890
30 8889990000
31 7778889999
34 5556667777
35 4445556666
40 5556667777

50
Query 11: Find Cid and CMobile from Customers who ordered any item and sort
the customer id in descending order

select Cid,CMobile From Customers


where Cid in (select customer_id from Orders2)
Order by Cid Desc

Output

Cid CMobile
40 5556667777
35 4445556666
34 5556667777
31 7778889999
30 8889990000
29 1234567890
28 4445556666
27 5556667777
26 6667778888
25 2223334444
24 7778889999
23 8889990000
22 1234567890
21 4445556666
19 2223334444
18 7778889999
17 8889990000
16 1112223333
13 2223334444
12 7778889999
11 8889990000
9 4445556666
8 6667778888

51
Query 12: Find the customer id and total number of orders by that customer

select customer_id, count(Order_id) as


Number_of_items_Ordered from Orders2
Group bycustomer_id
Order by
count(Order_id)DESC

Output

Cid Number_of_items_Ordered
29 6
13 3
27 2
23 2
24 2
8 2
9 2
11 2
12 2
17 2
30 2
31 1
34 1
35 1
40 1
18 1
19 1
21 1
22 1
25 1
26 1
28 1
16 1

52
Query 13: Find the details of customers who has done the trabsaction by Credit card
technique

SELECT c.* FROM Customers c


JOIN Transactions2 t
ON c.Cid = t.Order_id
WHERE t.Payment_method = 'Credit Card';

Output

Cid CName Cage CMobile CEmail CAddress


1 John Smith 28 1234567890 [email protected] 123 Main St
3 Michael Brown 42 5551234567 [email protected] 789 Oak St
16 Evelyn Johnson 32 1112223333 [email protected] 1010 Oak St
18 Abigail Davis 36 7778889999 [email protected] 1212 Elm St
10 Ava Smith 26 1234567890 [email protected] 444 Main St
12 Mia Davis 30 7778889999 [email protected] 666 Pine St
14 Charlotte Wilson 27 6667778888 [email protected] 888 Cedar St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
20 Sofia Anderson 34 5556667777 [email protected] 1414 Maple St
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St
23 Amelia Johnson 33 8889990000 [email protected] 1717 Elm St
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
13 Benjamin Thomas 43 2223334444 [email protected] 777 Elm St
14 Charlotte Wilson 27 6667778888 [email protected] 888 Cedar St
16 Evelyn Johnson 32 1112223333 [email protected] 1010 Oak St
20 Sofia Anderson 34 5556667777 [email protected] 1414 Maple St
21 Harper Martinez 28 4445556666 [email protected] 1515 Oak St

53
Query 14: Find number of users using different methods for transaction of money

select T.Payment_Method,count(C.Cid) as Number_of_users from Customers as C


join Transactions2 as T
On C.Cid = T.Order_id
Group by T.Payment_Method

Output

Payment_Method Number_of_Users
Credit Card 20
Debit Card 2
Google Pay 8
PayPal 8
Paytm 1

Query 15: Find the customer name who has ordered any one item by using correlated subquery

SELECT C.CName FROM Customers C


WHERE EXISTS (
SELECT * FROM Orders2 O
WHERE O.Customer_id = c.Cid
);
Output

CName
Sophia Anderson
James Martinez
Logan Thompson
Mia Davis
Benjamin Thomas
Evelyn Johnson
Jacob Smith
Abigail Davis
Liam Wilson
Harper Martinez
Ethan Taylor
Amelia Johnson
Logan Davis
Oliver Thomas
Mia Wilson
Lucas Brown
Evelyn Johnson
Jackson Smith
Ava Davis
Aiden Anderson
Scarlett Brown
Sebastian Thomas
Victoria Martinez

54
Query 16: Find the customer name and Customer id who has ordered any one item
by using correlated sub query

select C.Cid , C.Cname


from customers C
where exists (
select O.customer_id from Orders2 as O);

Output

Cid CName
1 John Smith
2 Emily Johnson
3 Michael Brown
4 Emma Davis
5 Daniel Wilson
6 Olivia Taylor
7 William Johnson
8 Sophia Anderson
9 James Martinez
10 Ava Smith
11 Logan Thompson
12 Mia Davis
13 Benjamin Thomas
14 Charlotte Wilson
15 Henry Brown
16 Evelyn Johnson
17 Jacob Smith
18 Abigail Davis
19 Liam Wilson
20 Sofia Anderson
21 Harper Martinez
22 Ethan Taylor
23 Amelia Johnson
24 Logan Davis
25 Oliver Thomas
26 Mia Wilson
27 Lucas Brown
28 Evelyn Johnson
29 Jackson Smith
30 Ava Davis
31 Aiden Anderson
32 Ella Martinez
33 Carter Wilson
34 Scarlett Brown
35 Sebastian Thomas
36 Luna Johnson
37 Grayson Davis
38 Penelope Wilson
39 Mateo Anderson
40 Victoria Martinez
41 Virat
55
Query 17: Find count of all customers ordered in the same date

select count(customer_id) as number_of_persons_ordered_that_date , Order_date


from Orders2
Group by Order_date;

Output

Number_of_persons_Ordered Order_Date
1 2023-01-07
1 2023-01-08
1 2023-01-09
1 2023-01-10
1 2023-01-11
1 2023-01-12
1 2023-01-13
1 2023-01-14
1 2023-01-16
1 2023-01-17
1 2023-01-18
1 2023-01-19
1 2023-01-20
1 2023-01-21
1 2023-01-22
1 2023-01-23
1 2023-01-24
1 2023-01-25
1 2023-01-26
1 2023-01-27
1 2023-01-28
1 2023-01-29
1 2023-01-30
1 2023-01-31
1 2023-02-01
1 2023-02-02
1 2023-02-03
1 2023-02-04
1 2023-02-05
1 2023-02-06
1 2023-02-07
1 2023-02-08
1 2023-02-09
1 2023-03-11
1 2023-05-01
1 2023-05-03
1 2023-05-05
1 2023-05-08
1 2023-05-10

56
Query 18: Find the details of transactions if it is present in the orders

select * from Transactions2


as T
where exists (
select Order_id from Orders2 as O where O.Order_id = T.Order_id);

Output

Transac_id Ord_id Pay_Date Pay_Method Amount


1 1 2023-05-01 Credit Card 50
2 12 2023-05-02 PayPal 75
3 3 2023-05-03 Credit Card 100
4 14 2023-05-04 Google Pay 20
6 16 2023-05-06 Credit Card 70
7 17 2023-05-07 PayPal 90
8 18 2023-05-08 Credit Card 80
9 9 2023-05-09 Google Pay 40
10 10 2023-05-10 Credit Card 120
11 10 2023-05-11 PayPal 60
12 12 2023-05-12 Credit Card 30
13 13 2023-05-13 Google Pay 110
14 14 2023-05-14 Credit Card 65
16 16 2023-05-16 PayPal 55
17 19 2023-05-17 Credit Card 85
18 18 2023-05-18 Google Pay 25
20 21 2023-05-20 PayPal 70
21 20 2023-05-21 Credit Card 120
22 25 2023-05-22 Google Pay 60
23 22 2023-05-23 Credit Card 40
24 23 2023-05-24 Credit Card 150
25 24 2023-05-25 PayPal 90
26 22 2023-05-26 Credit Card 80
27 28 2023-05-27 Google Pay 20
28 24 2023-05-28 Credit Card 100
29 19 2023-05-29 Credit Card 70
30 10 2023-05-30 PayPal 110
31 19 2023-05-31 Credit Card 65
32 12 2023-06-01 Google Pay 95
33 13 2023-06-02 Credit Card 55
34 14 2023-06-03 Credit Card 85
36 16 2023-06-05 Credit Card 135
37 19 2023-06-06 Google Pay 70
38 20 2023-06-07 Credit Card 120
39 21 2023-06-08 Credit Card 60
40 29 2023-06-09 PayPal 40
41 18 2023-06-09 Paytm 90
42 19 2023-05-09 Debit Card 100
43 20 2023-08-08 Debit Card 100

57
Query 19: Find the details of orders with product name for Order_id is 1

SELECT O.*,P.Product_name FROM OrderItemsTable2 O


JOIN Products P
ON O.Product_id = P.Product_id
WHERE O.Order_id=1;

Output

Ord_id P_id Quantity Price P_Name


1 4 2 25.99 Adidas Ultraboost

Query 20: Find the details of customers who has done the transaction between '2023-05-01'
and '2023-05-31'

SELECT c.* FROM Customers c


JOIN Transactions2 t
ON c.Cid = t.Order_id
WHERE t.Payment_date >= '2023-05-01' AND t.Payment_date <= '2023-05-31';

Output

Cid CName Cage CMobile CEmail CAddress


1 John Smith 28 1234567890 [email protected] 123 Main St
12 Mia Davis 30 7778889999 [email protected] 666 Pine St
3 Michael Brown 42 5551234567 [email protected] 789 Oak St
14 Charlotte Wilson 27 6667778888 [email protected] 888 Cedar St
16 Evelyn Johnson 32 1112223333 [email protected] 1010 Oak St
17 Jacob Smith 29 8889990000 [email protected] 1111 Pine St
18 Abigail Davis 36 7778889999 [email protected] 1212 Elm St
9 James Martinez 33 4445556666 [email protected] 333 Elm St
10 Ava Smith 26 1234567890 [email protected] 444 Main St
10 Ava Smith 26 1234567890 [email protected] 444 Main St
12 Mia Davis 30 7778889999 [email protected] 666 Pine St
13 Benjamin Thomas 43 2223334444 [email protected] 777 Elm St
14 Charlotte Wilson 27 6667778888 [email protected] 888 Cedar St
16 Evelyn Johnson 32 1112223333 [email protected] 1010 Oak St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
18 Abigail Davis 36 7778889999 [email protected] 1212 Elm St
21 Harper Martinez 28 4445556666 [email protected] 1515 Oak St
20 Sofia Anderson 34 5556667777 [email protected] 1414 Maple St
25 Oliver Thomas 38 2223334444 [email protected] 1919 Maple St
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St
23 Amelia Johnson 33 8889990000 [email protected] 1717 Elm St
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St
28 Evelyn Johnson 29 4445556666 [email protected] 2222 Elm St
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
10 Ava Smith 26 1234567890 [email protected] 444 Main St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St

58
Query 21: Find the details of customers who has ordered product id 4

SELECT C.* FROM Customers C


JOIN Transactions2 T
ON C.Cid = T.Order_id
JOIN OrderItemsTable2 o
ON T.Order_id = O.Order_id
WHERE O.Product_id = 4;

Output

Cid CName Cage CMobile CEmail CAddress


1 John Smith 28 1234567890 [email protected] 123 Main St
3 Michael Brown 42 5551234567 [email protected] 789 Oak St

Query 22: Find the details of products with category name and sort the price in
descending order

SELECT p.*,c.Category_name FROM Products p


JOIN Categories c
ON p.Category_id = c.Category_id
ORDER BY p.Price DESC;

Output

Pid PNmae Description Price Qua Cat_id Cat_Name


1 iPhone 12 Apple smartphone 999.99 10 1 Electronics
2 Samsung Galaxy S21 Android smartphone 899.99 15 1 Electronics
19 Sofa 3-seater couch 599.99 3 10 Furniture
20 Dining Table Wooden table with chairs 399.99 5 10 Furniture
6 Cookware Set Stainless steel pots and pans 199.99 8 3 Home & Kitchen
4 Adidas Ultraboost Running shoes 149.99 30 2 Clothing
3 Nike Air Max Running shoes 129.99 20 2 Clothing
5 Instant Pot Multi-cooker 79.99 5 3 Home & Kitchen
15 Car Jump Starter Portable power bank 79.99 10 8 Automotive
13 LEGO Star Wars Set Building blocks 59.99 18 7 Toys & Games
12 Dumbbell Set Weights for strength training 49.99 7 6 Sports & Fitness
18 Fitness Tracker Activity monitor 49.99 20 9 Health & Wellness
16 Car Floor Mats All-weather mats 39.99 15 8 Automotive
Board Game:
14 Monopoly Classic family game 29.99 25 7 Toys & Games
11 Yoga Mat Non-slip exercise mat 19.99 12 6 Sports & Fitness
Harry Potter and the
7 Sorcerer Stone Fantasy novel 12.99 50 4 Books
8 The Great Gatsby Classic novel 9.99 40 4 Books
17 Vitamin C Supplement Immune support 9.99 40 9 Health & Wellness
Beauty & Personal
9 Loreal Paris Mascara Volumizing mascara 8.99 25 5 Care
NIVEA Men Shaving Beauty & Personal
10 Cream For sensitive skin 4.99 30 5 Care

59
Query 23: Find all the customer id whose transaction amount is greater than 100

SELECT cid, SUM(t.Amount) AS


TotalAmount FROM Customers c
JOIN Transactions2 t
ON c.Cid = t.Order_id
GROUP BY c.Cid
HAVING SUM(t.Amount) > 100;

Output

Cid TotalAmount
10 290
12 200
13 165
14 170
16 260
18 195
19 390
20 340
21 130
22 120
23 150
24 190

Query 24: Find all the details of products whose stock quantity is less than 10

SELECT * FROM Products


WHERE stock_quantity < 10;

Output

Pid PNmae Description Price Qua Cat_id


5 Instant Pot Multi-cooker 79.99 5 3
Stainless steel pots and
6 Cookware Set pans 199.99 8 3
Weights for strength
12 Dumbbell Set training 49.99 7 6
19 Sofa 3-seater couch 599.99 3 10
20 Dining Table Wooden table with chairs 399.99 5 10

60
Query 25: Find the Customer id and total amount he had done transaction through
PayPal and only display if total amount is greater than 50

SELECT cid, SUM(t.Amount)


AS TotalAmount
FROM Customers c
JOIN Transactions2 t
ON c.Cid =t.Order_id
WHERE
t.Payment_method ='PayPal'
GROUP BY c.Cid
HAVING SUM(t.Amount) > 50;

Output

Cid Total Amount


10 170
12 75
16 55
17 90
21 70

Query 26: Find the Customer id and total amount he had done transaction through Google
Pay and only display for total amount is greater than 50

SELECT cid, SUM(t.Amount) AS


TotalAmount FROM Customers c
JOIN Transactions2 t
ON c.Cid = t.Order_id
WHERE
t.Payment_method
=
'Google Pay'
GROUP BY c.Cid
HAVING SUM(t.Amount) > 50;

Output
Cid Total Amount
12 95
13 110
19 70
25 60

61
Query 27: Find the Products along with category name which are in category

SELECT P.*,
C.Category_name FROM
Products P
JOIN Categories C ON P.Category_id = C.Category_id;

Output

Pid PName Description Price Qty Cat_id Cat_Name


1 iPhone 12 Apple smartphone 999.99 10 1 Electronics
2 Samsung Galaxy S21 Android smartphone 899.99 15 1 Electronics
3 Nike Air Max Running shoes 129.99 20 2 Clothing
4 Adidas Ultraboost Running shoes 149.99 30 2 Clothing
5 Instant Pot Multi-cooker 79.99 5 3 Home & Kitchen
Stainless steel pots and
6 Cookware Set pans 199.99 8 3 Home & Kitchen
Harry Potter and the
7 Sorcerer Stone Fantasy novel 12.99 50 4 Books
8 The Great Gatsby Classic novel 9.99 40 4 Books
Beauty & Personal
9 Loreal Paris Mascara Volumizing mascara 8.99 25 5 Care
NIVEA Men Shaving Beauty & Personal
10 Cream For sensitive skin 4.99 30 5 Care
11 Yoga Mat Non-slip exercise mat 19.99 12 6 Sports & Fitness
Weights for strength
12 Dumbbell Set training 49.99 7 6 Sports & Fitness
13 LEGO Star Wars Set Building blocks 59.99 18 7 Toys & Games
Board Game:
14 Monopoly Classic family game 29.99 25 7 Toys & Games
15 Car Jump Starter Portable power bank 79.99 10 8 Automotive
16 Car Floor Mats All-weather mats 39.99 15 8 Automotive
Vitamin C
17 Supplement Immune support 9.99 40 9 Health & Wellness
18 Fitness Tracker Activity monitor 49.99 20 9 Health & Wellness
19 Sofa 3-seater couch 599.99 3 10 Furniture
20 Dining Table Wooden table with chairs 399.99 5 10 Furniture

62
Query 28: Find all product id and product name for category Clothing

select Product_id , product_name from Products


P join Categories C
on P.Category_id = C.Category_id
where Category_name = 'Clothing';

Output

P_id P_Name
3 Nike Air Max
4 Adidas Ultraboost

Query 29: Create a view which contains category name and revenue of that items

CREATE VIEW CategoryRevenue1 As


SELECT c.Category_name, SUM(p.Price * o.Quantity) AS
TotalRevenue FROM Categories c
JOIN Products p
ON c.Category_id = p.Category_id
JOIN OrderItemsTable2 o
ON p.Product_id=o.Product_id
GROUP BY c.Category_name;

Output

Category_Name TotalRevenue
Automotive 159.97
Beauty & Personal Care 17.98
Clothing 1349.91
Furniture 1399.97
Health & Wellness 249.95
Sports & Fitness 59.97
Toys & Games 29.99

63
Query 30: Create a view which contains id,name and total transaction amount of customers

CREATE VIEW TopCustomers2 AS


SELECT c.Cid, c.Cname, SUM(t.Amount) AS
TotalAmount FROM Customers c
JOIN Transactions2 t
ON c.Cid = t.Order_id
GROUP BY c.Cid, c.Cname
select * from TopCustomers2;

Output

Cid CName Total_Transac_Amount


1 John Smith 50
3 Michael Brown 100
9 James Martinez 40
10 Ava Smith 290
12 Mia Davis 200
13 Benjamin Thomas 165
14 Charlotte Wilson 170
16 Evelyn Johnson 260
17 Jacob Smith 90
18 Abigail Davis 195
19 Liam Wilson 390
20 Sofia Anderson 340
21 Harper Martinez 130
22 Ethan Taylor 120
23 Amelia Johnson 150
24 Logan Davis 190
25 Oliver Thomas 60
28 Evelyn Johnson 20
29 Jackson Smith 40

64
Query 31: Create a view which contains customer name with Order id , Quantity , and
Product Name

CREATE VIEW CustomerOrderDetails AS


SELECT c.Cname, o.Order_id, o.Quantity,
p.Product_name FROM Customers c
JOIN Transactions2 t
ON c.Cid = t.Order_id
JOIN OrderItemsTable2 o
ON t.Order_id =o.Order_id
JOIN Products p ON o.Product_id = p.Product_id;
select * from CustomerOrderDetails;

Output

CName Order_id Order_Quantity Product_Name


John Smith 1 2 Adidas Ultraboost
Michael Brown 3 1 Adidas Ultraboost
Evelyn Johnson 16 1 Yoga Mat
Abigail Davis 18 1 Car Jump Starter
Evelyn Johnson 16 1 Yoga Mat
Liam Wilson 19 2 Yoga Mat
Abigail Davis 18 1 Car Jump Starter
Harper Martinez 21 2 Loreal Paris Mascara
Oliver Thomas 25 2 Car Floor Mats
Logan Davis 24 1 Board Game: Monopoly
Evelyn Johnson 28 3 Fitness Tracker
Logan Davis 24 1 Board Game: Monopoly
Liam Wilson 19 2 Yoga Mat
Liam Wilson 19 2 Yoga Mat
Evelyn Johnson 16 1 Yoga Mat
Liam Wilson 19 2 Yoga Mat
Harper Martinez 21 2 Loreal Paris Mascara
Jackson Smith 29 1 Sofa
Jackson Smith 29 2 Fitness Tracker
Abigail Davis 18 1 Car Jump Starter
Liam Wilson 19 2 Yoga Mat

65
Query 32: Find the customer name who had ordered any item by using Correlated subquery

SELECT C.CName
FROM
Customers asC
WHERE EXISTS
(
SELECT 1
FROM Orders2 O
WHERE O.customer_id = C.Cid
);

Output

CName
Sophia Anderson
James Martinez
Logan Thompson
Mia Davis
Benjamin Thomas
Evelyn Johnson
Jacob Smith
Abigail Davis
Liam Wilson
Harper Martinez
Ethan Taylor
Amelia Johnson
Logan Davis
Oliver Thomas
Mia Wilson
Lucas Brown
Evelyn Johnson
Jackson Smith
Ava Davis
Aiden Anderson
Scarlett Brown
Sebastian Thomas
Victoria Martinez

66
Query 33: Create a view which contains payment details with customer id

Create View Customer_payment_Details As


select customer_id , Payment_date , payment_method from
Orders2 as O join Transactions2 as T
On O.Order_id = T.Order_id;

Output

Cid Payment_Date Payment_Method


29 01-05-2023 Credit Card
12 02-05-2023 PayPal
29 03-05-2023 Credit Card
24 04-05-2023 Google Pay
26 06-05-2023 Credit Card
27 07-05-2023 PayPal
8 08-05-2023 Credit Card
9 09-05-2023 Google Pay
11 10-05-2023 Credit Card
11 11-05-2023 PayPal
12 12-05-2023 Credit Card
13 13-05-2023 Google Pay
24 14-05-2023 Credit Card
26 16-05-2023 PayPal
19 17-05-2023 Credit Card
8 18-05-2023 Google Pay
21 20-05-2023 PayPal
12 21-05-2023 Credit Card
25 22-05-2023 Google Pay
22 23-05-2023 Credit Card
23 24-05-2023 Credit Card
24 25-05-2023 PayPal
22 26-05-2023 Credit Card
28 27-05-2023 Google Pay
24 28-05-2023 Credit Card
19 29-05-2023 Credit Card
11 30-05-2023 PayPal
19 31-05-2023 Credit Card
12 01-06-2023 Google Pay
13 02-06-2023 Credit Card
24 03-06-2023 Credit Card
26 05-06-2023 Credit Card
19 06-06-2023 Google Pay
12 07-06-2023 Credit Card
21 08-06-2023 Credit Card
29 09-06-2023 PayPal
8 09-06-2023 Paytm
19 09-05-2023 Debit Card
12 08-08-2023 Debit Card

67
Query 34: Find the details of Orders which are done transactions

select * from
Orders2 O
where exists (
select Order_id from
Transactions2 T
where O.Order_id =T.Order_id
);

Output

Ord_id C_id Ord_Date Total_Amount


1 29 2023-05-01 250
3 29 2023-05-05 80
9 9 2023-01-09 65
10 11 2023-01-10 95
12 12 2023-01-12 85
13 13 2023-01-13 50
14 24 2023-01-14 75
16 26 2023-01-16 90
17 27 2023-01-17 100
18 8 2023-01-18 80
19 19 2023-01-19 70
20 12 2023-01-20 55
21 21 2023-01-21 65
22 22 2023-01-22 95
23 23 2023-01-23 120
24 24 2023-01-24 85
25 25 2023-01-25 50
28 28 2023-01-28 90
29 29 2023-01-29 100

68
Query 35:Create a view which contains customer id in table Orders

create view total_n_items_ordered


As
select O.customer_id from
Orders2 as O
Group by O.customer_id;
select * from total_n_items_ordered;

Output

Cid
8
9
11
12
13
16
17
18
19
21
22
23
24
25
26
27
28
29
30
31
34
35
40

69
Query 36: Find the details of customers and transaction date of that customer

select C.*,T.Payment_date from


Customers C
join Orders2 O
On
C.Cid = O.customer_id
join Transactions2asT
On T.Order_id = O.Order_id;

Output

Cid CName age CMobile CEmail CAddress P_Date


29 Jackson Smith 32 1234567890 [email protected] 2323 Cedar St 23-05-01
12 Mia Davis 30 7778889999 [email protected] 666 Pine St 23-05-02
29 Jackson Smith 32 1234567890 [email protected] 2323 Cedar St 23-05-03
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St 23-05-04
26 Mia Wilson 30 6667778888 [email protected] 2020 Oak St 23-05-06
27 Lucas Brown 36 5556667777 [email protected] 2121 Pine St 23-05-07
8 Sophia Anderson 29 6667778888 [email protected] 222 Pine St 23-05-08
9 James Martinez 33 4445556666 [email protected] 333 Elm St 23-05-09
11 Logan Thompson 35 8889990000 [email protected] 555 Oak St 23-05-10
11 Logan Thompson 35 8889990000 [email protected] 555 Oak St 23-05-11
12 Mia Davis 30 7778889999 [email protected] 666 Pine St 23-05-12
13 Benjamin Thomas 43 2223334444 [email protected] 777 Elm St 23-05-13
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St 23-05-14
26 Mia Wilson 30 6667778888 [email protected] 2020 Oak St 23-05-16
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St 23-05-17
8 Sophia Anderson 29 6667778888 [email protected] 222 Pine St 23-05-18
21 Harper Martinez 28 4445556666 [email protected] 1515 Oak St 23-05-20
12 Mia Davis 30 7778889999 [email protected] 666 Pine St 23-05-21
25 Oliver Thomas 38 2223334444 [email protected] 1919 Maple St 23-05-22
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St 23-05-23
23 Amelia Johnson 33 8889990000 [email protected] 1717 Elm St 23-05-24
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St 23-05-25
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St 23-05-26
28 Evelyn Johnson 29 4445556666 [email protected] 2222 Elm St 23-05-27
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St 23-05-28
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St 23-05-29
11 Logan Thompson 35 8889990000 [email protected] 555 Oak St 23-05-30
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St 23-05-31
12 Mia Davis 30 7778889999 [email protected] 666 Pine St 23-06-01
13 Benjamin Thomas 43 2223334444 [email protected] 777 Elm St 23-06-02
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St 23-06-03
26 Mia Wilson 30 6667778888 [email protected] 2020 Oak St 23-06-05
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St 23-06-06
12 Mia Davis 30 7778889999 [email protected] 666 Pine St 23-06-07
21 Harper Martinez 28 4445556666 [email protected] 1515 Oak St 23-06-08
29 Jackson Smith 32 1234567890 [email protected] 2323 Cedar St 23-06-09
8 Sophia Anderson 29 6667778888 [email protected] 222 Pine St 23-06-09
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St 23-05-09
12 Mia Davis 30 7778889999 [email protected] 666 Pine St 23-08-08
70
Query 37: Find Name,Mobile of customers and Order date of that customer

select C.Cname,C.CMobile ,O.Order_date from


customers as C join Orders as O
On C.Cid = O.customer_id;

Output

CName CMobile Order_Date


Jackson Smith 1234567890 2023-05-01
Jackson Smith 1234567890 2023-05-03
Jackson Smith 1234567890 2023-05-05
Jackson Smith 1234567890 2023-05-08
Jackson Smith 1234567890 2023-05-10

71
Query 38: Find the details of customers who has placed items in Orders

select * from Customers


where cid in (select cid from OrderItemsTable2);

Output

Cid CName age CMobile CEmail CAddress


1 John Smith 28 1234567890 [email protected] 123 Main St
2 Emily Johnson 35 9876543210 [email protected] 456 Elm St
3 Michael Brown 42 5551234567 [email protected] 789 Oak St
4 Emma Davis 31 7778889999 [email protected] 321 Pine St
5 Daniel Wilson 39 4445556666 [email protected] 567 Cedar St
6 Olivia Taylor 24 2223334444 [email protected] 890 Maple St
7 William Johnson 37 9998887777 [email protected] 111 Oak St
8 Sophia Anderson 29 6667778888 [email protected] 222 Pine St
9 James Martinez 33 4445556666 [email protected] 333 Elm St
10 Ava Smith 26 1234567890 [email protected] 444 Main St
11 Logan Thompson 35 8889990000 [email protected] 555 Oak St
12 Mia Davis 30 7778889999 [email protected] 666 Pine St
13 Benjamin Thomas 43 2223334444 [email protected] 777 Elm St
14 Charlotte Wilson 27 6667778888 [email protected] 888 Cedar St
15 Henry Brown 39 4445556666 [email protected] 999 Maple St
16 Evelyn Johnson 32 1112223333 [email protected] 1010 Oak St
17 Jacob Smith 29 8889990000 [email protected] 1111 Pine St
18 Abigail Davis 36 7778889999 [email protected] 1212 Elm St
19 Liam Wilson 25 2223334444 [email protected] 1313 Cedar St
20 Sofia Anderson 34 5556667777 [email protected] 1414 Maple St
21 Harper Martinez 28 4445556666 [email protected] 1515 Oak St
22 Ethan Taylor 41 1234567890 [email protected] 1616 Pine St
23 Amelia Johnson 33 8889990000 [email protected] 1717 Elm St
24 Logan Davis 27 7778889999 [email protected] 1818 Cedar St
25 Oliver Thomas 38 2223334444 [email protected] 1919 Maple St
26 Mia Wilson 30 6667778888 [email protected] 2020 Oak St
27 Lucas Brown 36 5556667777 [email protected] 2121 Pine St
28 Evelyn Johnson 29 4445556666 [email protected] 2222 Elm St
29 Jackson Smith 32 1234567890 [email protected] 2323 Cedar St
30 Ava Davis 37 8889990000 [email protected] 2424 Maple St
31 Aiden Anderson 31 7778889999 [email protected] 2525 Oak St
32 Ella Martinez 24 2223334444 [email protected] 2626 Pine St
33 Carter Wilson 39 6667778888 [email protected] 2727 Elm St
34 Scarlett Brown 28 5556667777 [email protected] 2828 Cedar St
35 Sebastian Thomas 35 4445556666 [email protected] 2929 Maple St
36 Luna Johnson 26 1234567890 [email protected] 3030 Oak St
37 Grayson Davis 40 8889990000 [email protected] 3131 Pine St
38 Penelope Wilson 27 7778889999 [email protected] 3232 Elm St
39 Mateo Anderson 33 2223334444 [email protected] 3333 Cedar St
40 Victoria Martinez 35 5556667777 [email protected] 3434 Maple St
41 Virat 30 NULL [email protected] Hyderabad

72
Query 39: Find the Order details whose customer address is 1212 Elm st

select * from Orders2 as O


where O.customer_id = (select C.Cid from Customers as C where Caddress = '1212 Elm st');

Output

Ord_id C_id Ord_Date Total_Amount


8 18 2023-01-08 55

73
Query 40: Find Order_id,Payment_date, and Amount from transactions using correlated
sub query

select Order_id,Payment_date,Amount
from Transactions2
where Exists (
select Order_id from Orders2);

Output

Ord_id Pay_Date Amount


1 2023-05-01 50
12 2023-05-02 75
3 2023-05-03 100
14 2023-05-04 20
16 2023-05-06 70
17 2023-05-07 90
18 2023-05-08 80
9 2023-05-09 40
10 2023-05-10 120
10 2023-05-11 60
12 2023-05-12 30
13 2023-05-13 110
14 2023-05-14 65
16 2023-05-16 55
19 2023-05-17 85
18 2023-05-18 25
21 2023-05-20 70
20 2023-05-21 120
25 2023-05-22 60
22 2023-05-23 40
23 2023-05-24 150
24 2023-05-25 90
22 2023-05-26 80
28 2023-05-27 20
24 2023-05-28 100
19 2023-05-29 70
10 2023-05-30 110
19 2023-05-31 65
12 2023-06-01 95
13 2023-06-02 55
14 2023-06-03 85
16 2023-06-05 135
19 2023-06-06 70
20 2023-06-07 120
21 2023-06-08 60
29 2023-06-09 40
18 2023-06-09 90
19 2023-05-09 100
20 2023-08-08 100

74
Query 41: Find the item_id,discount_amount,validity_start_date and validity_end_date
for the category id less than or equal to 5

select item_id,discount_amount,validity_start_date,validity_end_date from


Discounts where exists (select Product_id from Products
where Category_id <=5);

Output

item_id discount_amount validity_start_date validity_end_date


1 10 2023-06-01 2023-06-30
2 15.5 2023-07-01 2023-07-31
3 5.75 2023-06-15 2023-07-15
4 20 2023-06-01 2023-06-30
5 12.25 2023-06-15 2023-07-15
6 8.5 2023-07-01 2023-07-31
7 15 2023-06-01 2023-06-30
8 7.75 2023-06-15 2023-07-15
9 10.5 2023-07-01 2023-07-31
10 9 2023-06-01 2023-06-30
11 6.25 2023-06-15 2023-07-15
12 17.5 2023-07-01 2023-07-31
13 11.75 2023-06-01 2023-06-30
14 14 2023-06-15 2023-07-15
15 8.25 2023-07-01 2023-07-31
16 19.5 2023-06-01 2023-06-30
17 13.25 2023-06-15 2023-07-15
18 11.5 2023-07-01 2023-07-31
19 9 2023-06-01 2023-06-30
20 6.75 2023-06-15 2023-07-15

Query 42: Find the Product Name and Product Description for validate start

date is 2023-06-01

select P.product_name,P.Description from Products P Join Discounts D


On P.Product_id = D.item_id
where D.discount_amount = 10.00 and validity_start_date = '2023-06-01';

Output

P_Name P_Description
iPhone 12 Apple smartphone

75
Query 43: Find the discount percentage for flash deal promotion

select discount_percentage from


Promotions1
where Promotion_Name = 'Flash Deal';

Output

Discount_Percentage
20

Query 44: Find the nuber of items discount on same date

select count(item_id) as no_of_itemsdiscounts_on_same_date,validity_start_date from


Discounts
Group By validity_start_date
Having count(item_id) >=1;

Output

no_of_itemsdiscounts_on_same_date validity_start_date
7 2023-06-01
7 2023-06-15
6 2023-07-01

Query 45: Find the Promotion name and discount amount

select Pr.Promotion_Name,D.discount_amount from


Promotions1 as Pr
Join Discounts as D
On Pr.Promotion_Start_date = D.validity_start_date;

Output

Promotion_Name Discount_Amount
Summer Sale 10
Summer Sale 20
Summer Sale 15
Summer Sale 9
Summer Sale 11.75
Summer Sale 19.5
Summer Sale 9

76
Query 46: Find the Name of the brand for Brand id is 10

select Brand_name from


Brands
where Brand_id = 10;

Output
Brand_name
Skechers

Query 47: Find Brand id and Product Name whose price is greater than 100

select Brand_id,product_name from Products


as P
Join Brands as B
On
P.Product_id=B.Brand_id
where P.price > 100;

Output
Brand_id Product_Name
1 iPhone 12
2 Samsung Galaxy S21
3 Nike Air Max
4 Adidas Ultraboost
6 Cookware Set
19 Sofa
20 Dining Table

Query 48: Find Product id and Price whose Order

id is 18

select Product_id,Price from OrderItemsTable2


where Order_id = 18;

Output
Product_id Price
15 8.99

Query 49: Find the id and name of the customers whose mobile is not kept

in the database

select Cid,Cname from customers


where

Cmobile Isnull;

Output

Cid CName
41 Virat
77
Query 50: Create a view which contains rating is equal or greater than four

create view
All_Good_Rating_Members AS
select * from
Reviews2
where rating >= 4;
select * from All_Good_Rating_Members;

Output

Review_id Cid Pid Rating Comment Review_Date


1 10 4 4 Great product! 2023-05-01
2 2 4 5 Excellent service! 2023-05-03
5 19 4 5 Highly recommended! 2023-05-10

78
SQL QUERIES:
Query1: Find the second most country, points
select COUNTRY,POINTS from POINTSTABLE where POINTS=
(
select max(POINTS)from POINTSTABLE where POINTS<>
(
select max(POINTS)from POINTSTABLE
)
)
/*output:
M_id M_name DID M_gender M_Address M_Mobile HID
601 shriya 1 F tirupathi 9998886661 101
602 keishna 2 M chennai 9998886662 102
603 meera 3 F kerala 9998886663 103
604 tarun 4 M chennai 9998886664 104
605 jansi 5 F tirupathi 9998886665 105
606 rupa 5 F tirupathi 9998886666 106

79
607 divya 1 F mumbai 9998886667 107
608 pradeepthi 2 F hyderabad 9998886668 108
609 reshma 3 F vijayawada 9998886669 109
610 deepak 4 M kerala 9998886610 110
611 raj 5 M chennai 9998886611 111
612 padma 1 F Bhopal 9998886612 112
613 karthik 2 M vizag 9998886613 113
614 neha 3 F vijayawada 9998886614 114
615 yeshwanth 4 M bangalore 9998886615 115
*/

Query2: Insert a coloumn name called Blood group with data type of varchar (10) and
constrain as null in customer table,manager table and staff table.
alter table customer add BloodGroup varchar (10) null
alter table manager add BloodGroup varchar (10) null
alter table staff add BloodGroup varchar (10) null

/*output:
s_sid s_name DID s_mobile BloodGroup
501 vicky 1 8889997771 NULL
502 ram 2 8889997772 NULL
503 kiran 3 8889997773 NULL
504 sunny 4 8889997774 NULL
505 vijay 5 8889997775 NULL
506 mahi 1 8889997776 NULL
CID CName Cmobile age crating BloodGroup
401 hima 9997776661 18 7 NULL
402 harshitha 9997776662 19 7 NULL
403 janu 9997776663 20 7 NULL
404 poojitha 9997776664 18 6 NULL
405 sreekar 9997776665 21 8 NULL
M_id M_name DID M_gender M_Addres M_Mobile HID

BloodGroup
601 shriya 1 F tirupathi 9998886661 101 NULL

80
60 keishna 2 M chennai 9998886662 102 NULL
603 meera 3 F kerala 9998886663 103 NULL
60 tarun 4 M chennai 9998886664 104 NULL
605 jansi 5 F tirupathi 9998886665 105 NULL
606 rupa 5 F tirupathi 9998886666 106 NULL
*/

Query3: Display the total cost of all facities which are avilable.
selectsum(F_cost)fromFacilities_available
/*output
(Nocolumnname)
21200.00 */
Query4:Display the details of customer who has given rating more than 7.
select * from customer where crating>7
/* output:
CName Cmobile age crating CID BloodGroup
sreekar 9997776665 21 8 405 NULL
rithu 9997776666 30 9 406 NULL
abhi 9997776667 40 10 407 NULL
rohan 9997776668 37 10 408 NULL
priya 9997776612 88 8 412 NULL
nitya 9997776613 78 10 413 NULL
jayanth 9997776614 68 9 414 NULL
rujith 9997776615 70 9 415 NULL */

Query5: Create view as hotel_manager whose address is tirupathi and update view
and drop the view.
create view hotel_manager from Manager as
select M_id, M_name, M_gender
from Manager where address='tirupathi'
select * from hotel_manager

/* output:
M_id M_name M_gender

81
601 shriya F
605 jansi F
606 rupa F

update manager set M_name='dhanya' where M_id=605


/* output:
M_id M_name M_gender
601 shriya F
605 dhanya F
606 rupa F

drop view hotel_manager


/* Output: Commands completed successfully*/

Query6: Find the total no:of customers whose age is greater than 60 and rating=9
select count(CID) from customer where age>60 and crating=9
/* output:
(No column name)
2 */
Query7: Find the ID's of customer whose contact is null.
select CID from customer where contact=null.
/* output:
CID
*/
Query8: Find the age and names of customers whose name begin and ends with p
and a and having atleast three characters.
select c.CName, c.age from customers c where CName like 'p_%a'
/* output:
CName age
Poojitha 18
priya 88 */
Query9: Find the ID's and names of customers who have given rating more than 8.
select c.CID, c.CName from customers c where rating>8
/* output:
CID CName
406 rithu

82
407 abhi
408 rohan
413 nitya
414 jayanth
415 rujith */

Query10: Display the names of facilties that are available.


select F_name from Facilities_available
/* output:
F_name
food
internet
books
computer
laundry
meeting facilities
car parking
catering
water purifier
house keeping */
Query11: Display the total count of staff members.
select count(s_sid) as staff_count from staff
/* output:
staff_count
15 */
Query12: Display the names and mobile number of male managers.
select m.M_name, m.M_Mobile from manager m where M_gender='F'
/*output:
M_name M_Mobile
keishna 9998886662
tarun 9998886664
deepak 9998886610
raj 9998886611
karthik 9998886613
yeshwanth 9998886615 */

83
Query13: Display the names of departments using order by statement.
select Dname from Depart order by Dname asc

/* output:
Dname
food
house keeping
management
security
service */
Query14: Find the details of the customer whose age is between 20 and 30.
select * from customers where age between 20 and 30
/* output:
CID CName Cmobile age crating
403 janu 9997776663 20 7
405 sreekar9997776665 21 8
406 rithu 9997776666 30 9 */

Query15: find the ID and name of managers who belong to department 5 and
tirupathi.
select M_id, M_name from manager where DID=5 and M_Address='tirupathi'
/* output:
M_id M_name
605 jansi
606 rupa */
Query16: Find the total number of hotels that are in this city.
SELECT COUNT(HID) AS num_hotels FROM Hotel;

/* output:
num_hotels
15 */
Query17: Update the contact of a particular staff.
update staff set s_mobile='7672044500' where s_sid=513
/* output:

84
s_sname DID s_mobile s_sid
vicky 1 8889997771 501
ram 2 8889997772 502
kiran 3 8889997773 503
sunny 4 8889997774 504
vijay 5 8889997775 505
mahi 1 8889997776 506
ravi 2 8889997777 507
arpitha 3 8889997778 508
ramya 4 8889997779 509
siri 5 8889997710 510
adhi 1 8889997711 511
keerthi 2 8889997712 512
anshu 3 7672044500 513
akrythi 4 8889997714 514
ashok 5 8889997715 515 */

Query18: Insert a column name called R_cost with datatype as money and constraint
as null in rom table and insert values in it.
alter table Room add R_cost money null
update Room set R_cost=3000 where R_number=10 or R_number=12 or R_number=13
update Room set R_cost=3250 where R_number=17 or R_number=19 or R_number=20
update Room set R_cost=3500 where R_number=23 or R_number=24 or R_number=26
update Room set R_cost=3750 where R_number=27 or R_number=30 or R_number=31
update Room set R_cost=4000 where R_number=34 or R_number=37 or R_number=40
/* output:
R_type R_number R_floor R_cost
A 10 1 3000.00
A 12 1 3000.00
A 13 2 3000.00
A 17 4 3250.00
A 19 3 3250.00
A 20 3 3250.00

85
N 23 2 3500.00
N 24 2 3500.00
N 26 5 3500.00
N 27 5 3750.00
N 30 4 3750.00
N 31 3 3750.00
N 34 1 4000.00
N 37 2 4000.00
A 40 2 4000.00 */

Query19: Find the name of the hotel whose name starts with b and having atleast five
characters.
select Hname from hotel where Hname like 'b_%'
/* output:
Hname
baghvan
banjaar */
Query20: Display the average of all the facilities costs.
select avg(F_cost) as Avg_fac_cost from Facilities_available
/* output:
Avg_fac_cost
2120.00 */
Query21: Find the mobile number of staff whose name ends with i.
select s_mobile from staff where s_name like '%i'
/* output:
s_mobile
8889997776
8889997777
8889997710
8889997711
8889997712
8889997714 */

86
Query22: create a view from customers which includes CID, CName and mobile
number of customers of age >=30.
create view customer_details as
select CID, CName, Cmobile
from customers where age>=30
select * from customer_details
/* output:
CID CName Cmobile
406 rithu 9997776666
407 abhi 9997776667
408 rohan 9997776668
411 rehman9997776611
412 priya 9997776612
413 nitya 9997776613
414 jayanth9997776614
415 rujith 9997776615 */

Query23: Find the booking id of customer who booked the room 19.
select b.B_id from Booking b, Room r where b.R_number=r.R_number and
r.R_number=19
/* output:
B_id
305 */
Query24: Display the top five cid's of customers.
select top(5) CID from customer

/* output:
CID
101
102
103
104
105 */

87
Query25: Find the ID's and count of ID's of customers whose age is greater than 25
( use group by statement).
select CID, count(CID) as count from customers
where age>25 group by CID
/* output:
CID count
406 1
407 1
408 1
411 1
412 1
413 1
414 1
415 1
416 1
417 1 */

Query 26: Find names of manager of hotel.


select M_name from manager m, hotel h where h.HID=m.HID
/*output:
M_name
shriya
keishna
meera
tarun
divya
pradeepthi
reshma
deepak
padma
karthik
neha */
Query 27: Find the staff who belongs to food department

88
select s_name from staff s,Depart D where D.Dname='food' and s.DID=D.DID
/*output:
s_name
ram
ravi
keerthi */

Query 28: Display the names of mangers who belongs to security and house keeping
department. ( use UNION)
select m.M_name from manager m,Depart D,hotel h where D.Dname='security'
and m.DID=D.DID and m.HID=h.HID
UNION
select m.M_name from manager m,Depart D,hotel h where D.Dname='house keeping'
and m.DID=D.DID and m.HID=h.HID
/*output:
M_name
meera
neha
reshma */
Query 29: Find the booking id who booked roomtype as ac.
select b.B_id from Room r,Booking b where b.R_number=r.R_number and r.R_type='A'
/*output:
B_id
301
302
303
304
305
306
315*/
Query 30: Find cid, cname and from customer whose age is minimum
select CID,CName,age from customers where age=(select min(age) from customers)
/*output:

89
CID CName age
410 shetal 10 */

Query31: Display the total no of departments


Select count (DID) from Depart
/* output:
(No column name)
5 */

90
CHAPTER 4. CONCLUSION AND FUTUREWORK

Conclusion
In conclusion, the toll plaza database schema presented above provides a solid foundation
for managing and maintaining a toll plaza system. It encompasses essential entities such as
toll plazas, lanes, vehicles, customers, transactions, payments, users, roles, admin,
operators, supervisors, audit logs, vehicle owners, vehicle registration, toll plaza operators,
toll rates, toll violations, and toll violation fines.By utilizing this database schema, the toll
plaza system can efficiently store and retrieve information about toll plaza locations, lanes,
vehicle types, customers, and transactions. It enables the system to track and record details
of each transaction, including the vehicle involved, the toll plaza and lane used, the
customer responsible, and the corresponding payment.The inclusion of tables such as
vehicle owners and vehicle registration allows for the management of vehicle ownership
and registration details, providing a comprehensive view of vehicle-related information
within the toll plaza.
Overall, this database schema promotes efficient data management, accurate transaction
tracking, and robust user access control for a toll plaza system. It serves as a foundation
for implementing additional features and functionalities to meet specific requirements and
improve the overall operation and maintenance of the toll plaza system.

Future Work
In the future, the toll plaza database can be further enhanced to incorporate advanced
technologies and features. One area of future work involves the integration of artificial
intelligence (AI) and machine learning (ML) algorithms. By leveraging AI and ML, the
toll plaza database can analyze historical transaction data, traffic patterns, and user
behavior to predict traffic congestion, optimize toll rates, and allocate resources effectively.
Additionally, the database could be expanded to include geospatial data, allowing for more
precise location-based analytics and the implementation of dynamic tolling strategies.
Another potential advancement is the integration of blockchain technology to enhance
security, transparency, and trust in toll plaza transactions. By utilizing blockchain, the toll
plaza database can securely store transaction records, verify the authenticity of payments,
and enable secure peer-to-peer transactions. Furthermore, the future work could involve
the development of mobile applications or web portals that allow users to access their
transaction history, make payments, and receive personalized notifications and offers. This
would improve the overall user experience and provide convenience and flexibility for toll
plaza users.

91

You might also like