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

SQL 1

Uploaded by

Nikhil Verma
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)
13 views

SQL 1

Uploaded by

Nikhil Verma
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/ 3

KPI 1: Weekday vs.

Weekend Payment Statistics


Total Orders: Weekday vs. Weekend
 Purpose: This query helps us understand customer purchasing behavior , specifically whether
customers are more active during weekdays or weekends. This information can be used to
schedule promotions, marketing campaigns, and operational support more e ectively.

 Explanation:
o CASE is used to categorize orders into 'Weekday' or 'Weekend' based on the day of the
week.
o DAYOFWEEK extracts the day number from the order's purchase date.
o Days 2 to 6 are considered weekdays (Monday to Friday), while others are weekends.
o COUNT(order_id) counts the total orders for each category.
o GROUP BY groups the results by 'Weekday' or 'Weekend' to display the total orders for
each.
Average Payment Value: Weekday vs. Weekend
 Purpose: Analyzing the average spending amount helps identify if there is a di erence in the
payment value during weekends versus weekdays. This insight allows businesses to focus on
driving higher-value transactions during slower periods.

 Explanation:
o Similar CASE logic is used to categorize payments as 'Weekday' or 'Weekend'.
o AVG(payment_value) calculates the average payment amount for each group.
o JOIN is used to connect the orders with payment details.
o GROUP BY ensures the calculation is done separately for weekday and weekend
payments.

KPI 2: Total Number of Orders with Review Score 5 and Payment Type as Credit Card
 Purpose: : This query focuses on identifying highly satisfied customers who use credit cards
for their purchases. Understanding this helps businesses understand which payment methods
are correlated with high satisfaction, potentially guiding loyalty programs or targeted
incentives.
 Explanation:
o JOIN statements link the reviews, orders, and payments tables to access all necessary
information.
o WHERE clause filters for orders with a review score of 5 and payment type as
'credit_card'.
o COUNT(DISTINCT o.order_id) counts each unique order that meets the criteria,
ensuring no duplicate orders are counted.

KPI 3: Average Delivery Days for Pet Shop Products


 Purpose: To calculate the average delivery time specifically for products from the 'pet shop'
category.
 Explanation:
o DATEDIFF calculates the number of days between the purchase date and the delivery
date.
o AVG is used to find the average delivery days across all pet shop products.
o JOIN connects products, order items, and orders data to filter only those related to 'pet
shop'.
o WHERE clause ensures only delivered orders are considered in the calculation.
KPI 4: Average Price and Payment Values from Customers of São Paulo
 Purpose: The goal here is to understand the spending patterns of São Paulo customers, a key
demographic for the business. It helps to tailor marketing strategies and better meet the needs
of this region.
 Explanation:
o Subquery 1 calculates the average product price paid by São Paulo customers.
 ROUND(AVG(oi.price), 2) provides a rounded average of product prices.
 JOIN links customer, order, and order item data to access pricing information.
 WHERE ensures only customers from São Paulo are included.
o Subquery 2 calculates the average payment value.
 ROUND(AVG(op.payment_value), 2) computes the average payment value.
 Similar JOIN and WHERE conditions ensure consistency with customer location.
o Both subqueries are combined using a SELECT statement to present the results
together.

KPI 5: Relationship Between Shipping Days vs. Review Scores


 Purpose: To determine if the speed of delivery has a direct impact on customer satisfaction,
represented by review scores. This can help prioritize faster delivery methods to improve
ratings.
 Explanation:
o DATEDIFF calculates the days between the purchase and delivery.
o ROUND(AVG(...), 0) computes the average shipping days for each review score, rounded
to a whole number.
o GROUP BY groups the results by each review score to display the average shipping time
for each score.
o ORDER BY sorts the scores for easier interpretation.

KPI 6: Total Orders, Price, Freight Value, and Total Amount


 Purpose: This query gives an overview of sales performance, including total sales, shipping
costs, and combined revenue. It helps in understanding the business's overall revenue and
logistics cost e iciency.

 Explanation:
o COUNT(order_id) gives the total number of orders.
o SUM(price) and SUM(freight_value) calculate the cumulative value of sales and
shipping fees.
o ROUND(... / 1000000, 2) converts these totals into millions for a more readable format.
o Calculations are combined to show Total Price, Total Freight Value, and Total Amount.

KPI 7: Most Used Payment Type


 Purpose: To identify the most popular payment methods among customers. This helps to
improve the checkout process and ensure that the preferred payment methods are well-
supported.

 Explanation:
o COUNT(order_id) counts how often each payment method was used.
o GROUP BY payment_type categorizes the counts by each type of payment.
o This query identifies which payment methods are most frequently used by customers.

KPI 8: Yearly Approved Orders


 Purpose: Understanding the number of orders approved each year helps in analyzing growth
trends, seasonal fluctuations, and setting sales targets. This information is valuable for
strategic planning and forecasting.

 Explanation:
o YEAR(...) extracts the year from the order approval date.
o COUNT(order_id) counts the number of orders approved each year.
o WHERE filters out any orders where the approval date is missing.
o GROUP BY Year groups counts by each year.
o ORDER BY Year sorts the results chronologically.

KPI 9: Top 5 Product Categories with Most 5-Star Reviews


 Purpose: Identifying which product categories receive the most 5-star reviews helps the
business focus on its strengths, using customer satisfaction as a marketing advantage.

 Explanation:
o JOIN clauses: Links order items, reviews, and products datasets.
o WHERE clause: Filters to include only 5-star reviews.
o COUNT function: Counts the number of 5-star reviews per product category.
o ORDER BY and LIMIT: Orders the results by the count and limits it to the top 5.

KPI 10: Top 5 Product Categories with Most 1-Star Reviews


 Purpose: This query helps identify areas for improvement by highlighting the product
categories with the most dissatisfaction. It allows the business to take targeted actions to
address customer complaints and improve product quality.
 Explanation:
o Similar structure to KPI 9, but WHERE r.review_score = 1 focuses on 1-star reviews.
o It highlights which product categories might need quality improvement or further
investigation.
o The ORDER BY and LIMIT ensure that only the top 5 categories with the most 1-star
reviews are shown.

You might also like