Assignment 05
Assignment 05
Operators
Instructions:
Please share your answers filled in line in the Word document. Submit
code separately wherever applicable.
1. Create a Supermart_DB with the tables created from the datasets shared
(Customer.csv, Sales.csv and Product.csv files)
a. Create a new database in your database management system, and
name it Supermart_DB.
b. Create a new table called "customers" in the Supermart_DB
database
c. Load the data from the Customer.csv file into the customers table
d. Create a new table called "products" in the Supermart_DB
database
e. Load the data from the Product.csv file into the products table
f. Create a new table called "sales" in the Supermart_DB database
g. Load the data from the Sales.csv file into the sales table
GROUP BY OPERATORS:-
1. Create a display with the information below for each product ID.
a. Total sales (in $) order by this column in descending
b. Total sales quantity
c. The number of orders
d. Max Sales value
e. Min Sales value
f. Average sales value
2. Get the list of product ID’s where the quantity of product sold is greater
than 10
1.)
CREATE DATABASE Supermart_DB;
USE Supermart_DB;
a)
SELECT DISTINCT City
FROM customers
WHERE Region IN ('North', 'East');
b)
SELECT *
FROM sales
WHERE TotalAmount BETWEEN 100 AND 500;
c)
1)
SELECT *
FROM orders
WHERE discount > 0
ORDER BY discount DESC;
2)
SELECT *
FROM orders
WHERE discount > 0
ORDER BY discount DESC
LIMIT 10;
Aggregate operators:-
1)
SELECT SUM(sales) AS total_sales
FROM sales;
2)
SELECT COUNT(*) AS customer_count
FROM customers
3)
SELECT AVG(age) AS average_age
FROM customers
WHERE region = 'east';
4)
SELECT MIN(age) AS min_age, MAX(age) AS max_age
FROM customers
WHERE city = 'Philadelphia';
GROUP BY OPERATORS:-
1)
SELECT
product_id,
SUM(sales) AS total_sales,
SUM(quantity) AS total_quantity,
COUNT(*) AS num_orders,
MAX(sales) AS max_sales,
MIN(sales) AS min_sales,
AVG(sales) AS avg_sales
FROM
sales
GROUP BY
product_id
ORDER BY
total_sales DESC;