Mentorness Internship Task-2
Mentorness Internship Task-2
Mentorness Internship Task-2
INTERNSHIP
P R E S E N T E D BY M D M O H S H I N K H A N
SQL PROJECT
WALMART SALES ANALYSIS (TASK 2)
SQL
Solution
SELECT * FROM Walmart_Sales WHERE
Branch = 'A';
2.Write a SQL query for find the
total sales for each product line.
Solution
SELECT Product_line, SUM(Total) AS
Total_Sales FROM walmart_sales
GROUP BY Product_line;
3.Write a SQL query for list all
sales transactions where the
payment method was 'Cash'
Solution
SELECT *FROM walmart_sales
WHERE Payment = 'Cash';
Ingoude
Compan
y
4.Write a SQL query for calculate
the total gross income generated
in each city
Solution
uSELECT City, SUM(gross_income) AS
Total_Gross_Income FROM
walmart_sales GROUP BY City;
5.Write a SQL query for find the
average rating given by customers
in each branch
Solution
SELECT Branch, AVG(Rating) AS
Average_Rating FROM walmart_sales
GROUP BY Branch;
6.Write a SQL query for determine
the total quantity of each product
line sold.
Solution
SELECT Product_line, SUM(Quantity)
AS Total_Quantity_Sold FROM
walmart_data GROUP BY Product_line;
7.Write a SQL query for list the top
5 products by unit price.
Solution
SELECT Product_line, Unit_price FROM
walmart_data ORDER BY Unit_price
DESC LIMIT 5;
8.Write a SQL query for find sales
transactions with a gross margin
percentage greater than 30%.
Solution
SELECT * FROM walmart_data WHERE
gross_margin_percentage > 30;
9.Write a SQL query for retrieve
sales transactions that occurred on
weekends.
Solution
SELECT * FROM walmart_data WHERE
STRFTIME('%w', Date) IN ('0', '6');
10.Write a SQL query for Calculate
the total sales and gross income
for each month.
Solution
SELECT STRFTIME('%Y-%m', Date) AS
Month, SUM(Total) AS Total_Sales,
SUM(gross_income) AS
Total_Gross_Income FROM
walmart_data GROUP BY
STRFTIME('%Y-%m', Date) ORDER BY
Month;
11.Write a SQL query for find the
number of sales transactions that
occurred after 6 PM
Solution
SELECT COUNT(*) AS
Transactions_After_6PM FROM
walmart_data WHERE STRFTIME('%H',
Time) >= '18';
12.Write a SQL query for list the
sales transactions that have a
higher total than the average total
of all transactions
Solution
SELECT * FROM walmart_data WHERE
Total > (SELECT AVG(Total) FROM
walmart_data);
13.Write a SQL query for find
customers who made more than 5
purchases in a single month
Solution
SELECT Customer_type,
STRFTIME('%Y-%m', Date) AS Month,
COUNT(*) AS Number_of_Purchases
FROM walmart_data GROUP BY
Customer_type, STRFTIME('%Y-%m',
Date) HAVING COUNT(*) > 5;
14.Write a SQL query calculate the
cumulative gross income for each
branch by date.
Solution
SELECT Branch, Date,
SUM(gross_income) OVER (PARTITION
BY Branch ORDER BY Date) AS
cumulative_gross_income FROM
walmart_data ORDER BY Branch,
Date;
15.Find the total cogs for each
customer type in each city.
Solution
SELECT City, Customer_type,
SUM(cogs) AS total_cogs FROM
walmart_data GROUP BY City,
Customer_type ORDER BY City,
Customer_type;