Exam Database _
Exam Database _
Tasks:
1. Task: "Write an SQL query to display the ProductName, Price, and CategoryName of all
products in the 'Electronics' category. (Assume CategoryName is in the Categories table,
and you need to join)."
2. Task: "Write an SQL query to find the total revenue generated by each product,
displaying the ProductName and the total revenue (Quantity * UnitPrice from
OrderItems). Sort the results in descending order of revenue." (Requires joins,
aggregation, and sorting).
3. Task: "Write an SQL query to list all customers who registered in the last 30 days and
who have placed at least one order. Display CustomerName, RegistrationDate, and the
number of orders placed." (Requires date functions, subqueries or joins with
aggregation, and filtering).
4. Task: "Write an SQL query to update the 'Stock' of a specific ProductID (provide an
example ProductID) based on the quantities ordered in the 'OrderItems' table. Reduce
the stock by the sum of quantities ordered for that product. (Requires subqueries or joins
with aggregation and updates)."
5. Task: "Write an SQL query to create a view named 'CustomerOrderSummary' that
displays CustomerName, OrderID, OrderDate, and the total amount of each order (sum
of Quantity * UnitPrice). Then, write a query to select all data from that view." (Requires
view creation and selection).
6. Task: "Write an SQL query to find all products that have never been ordered. Display the
ProductName and ProductID." (Requires subqueries or left joins).
7. Task: "Write an SQL query to find the average order value for each city. Display the City
and the average order value." (Requires joins, aggregation, and grouping).
8. Task: "Write an SQL query to find the category, and the number of products within that
category, including parent categories. Display the CategoryName and the number of
products." (Requires self joins, and aggregation).
Expectations :
● Multiple Joins:
○ Tasks require joining multiple tables (e.g., Products, OrderItems, Orders,
Customers, Categories).
● Aggregation and Grouping:
○ Tasks involve using aggregate functions (SUM, AVG, COUNT) and grouping
results.
● Subqueries:
○ Tasks may require the use of subqueries to filter or calculate data.
● Date Functions:
○ Tasks involve working with date data and using date functions.
● Views:
○ Tasks require creating and using database views.
● Data Updates based on other tables:
○ Tasks require the student to update data in one table, based on the data within
another table.
● Hierarchical Data:
○ The categories table contains parent categories, adding a layer of complexity.
● Data Creation :
○ You are supposed to create enough tables to fulfil all the requirements and also
create enough records to fulfil queries.
○ Data should be enough and user understandable.
○
●