This SQL project focuses on a sales analysis of a coffee shop, covering multiple key aspects such as total sales, order counts, and trends over time. Here's a breakdown of the project:
- A database
Coffee_shop_Sales
is created to store sales data. - The project uses a
Coffee_Sales
table for querying and analysis.
- Data Type Checks: Inspects the columns of
Coffee_Sales
using:sp_help 'Coffee_Sales'
INFORMATION_SCHEMA.COLUMNS
- Alterations:
transaction_date
is altered toDATE
.transaction_time
is altered toTIME
.
- For each month (January to December), total sales are calculated using
SUM(transaction_qty * unit_price)
. - Extracts the month from
transaction_date
usingMONTH()
to filter sales by specific months.
- Sales Trend Analysis:
- Calculates month-on-month sales differences using the
LAG()
function to compare current sales with the previous month.
- Calculates month-on-month sales differences using the
- Order Count Trends:
- Calculates the number of transactions (orders) for each month using
COUNT(transaction_id)
.
- Calculates the number of transactions (orders) for each month using
- Total Quantity Sold: Computes the total quantity sold in each month using
COUNT(transaction_qty)
. - Month-on-Month Quantity Trends: Uses
LAG()
to track increases or decreases in sold quantities.
- Combines multiple metrics (quantity, transactions, sales) in a single query:
- Uses
CONCAT()
andROUND()
to present totals in thousands (e.g.,1k
for 1000).
- Uses
- Uses
DATEPART(WEEKDAY, transaction_date)
to analyze sales performance on weekends versus weekdays. - Compares sales totals on weekends (Saturday, Sunday) with weekdays.
- Analyzes total sales for each store location on a monthly basis.
- Ranks sales by location using
GROUP BY store_location
.
- Daily Sales: Calculates total sales for each day of the month using
DAY(transaction_date)
. - Hourly Sales: Summarizes sales by the hour using
DATEPART(HOUR, transaction_time)
.
- Monthly Averages: Calculates the average sales for each month using
AVG()
.
- Product Category: Summarizes total sales by product categories (e.g., coffee, snacks) for each month.
- Product Type: Calculates sales for different product types using
GROUP BY product_type
.
- Weekday Sales Breakdown: Assigns meaningful labels (e.g., "Monday," "Tuesday") to sales based on the day of the week using
CASE
statements. - Sales trends by weekday for the month of May.
- Aggregations:
SUM()
,COUNT()
,AVG()
- Date/Time Handling:
MONTH()
,DAY()
,DATEPART(WEEKDAY)
- Window Functions:
LAG()
for month-on-month comparisons. - Grouping:
GROUP BY
for summarizing sales by month, product, store, and time. - Conditional Statements:
CASE
for categorizing weekday vs. weekend sales.
This project provides an in-depth analysis of coffee shop sales data, tracking monthly sales trends, order counts, and performance based on time (day, week, hour). It also covers product-based and location-based sales insights, making it a comprehensive exploration of sales metrics.