Blog – Maggie Zeng Data analysis,SQL Sales Data Analysis with SQL

Sales Data Analysis with SQL

In the realm of data-driven decision-making, Structured Query Language (SQL) serves as a fundamental tool for effective data analysis and business intelligence. SQL empowers organizations to extract valuable insights from vast datasets, enabling informed strategic decisions. Its versatility in handling complex queries, aggregations, and transformations makes it indispensable in navigating the complexities of a data-centric environment.

This project focuses on analyzing sales data using SQL, aiming to uncover patterns, trends, and key performance indicators, contributing valuable information for informed business decisions and strategic planning.

This dataset consists of 10 columns:
Order ID – A unique ID for each order placed on a product
Product – Item purchased
Quantity Ordered – Describes how many of that products are ordered
Price Each – Unit price of product
Order Date – Date on which the order is placed
Purchase Address – Address to where the order is shipped
Month, Sales, City, Hour – Extra attributes formed from the above.


Below is a sample of the data

Order IDProductQuantity
Ordered
Price
Each
Order DatePurchase AddressMonthSalesCityHour
295665Macbook Pro Laptop11700.02019-12-30 00:01:00136 Church St, New York City, NY 10001121700.0New York City0
295666LG Washing Machine1600.02019-12-29 07:03:00562 2nd St, New York City, NY 1000112600.0New York City7
295669USB-C Charging Cable111.952019-12-18 12:38:0043 Hill St, Atlanta, GA 303011211.95Atlanta12
29566827in FHD Monitor1149.992019-12-22 15:13:00410 6th St, San Francisco, CA 9401612149.99San Francisco15
295667USB-C Charging Cable111.952019-12-12 18:21:00277 Main St, New York City, NY 100011211.95New York City18
295670AA Batteries (4-pack)13.842019-12-31 22:58:00200 Jefferson St, New York City, NY 10001123.84New York City22

Because of the inherent presence of strings in databases, we start by converting these strings into numerical values.

update Sales_Data set month = cast(month as integer);

 

First, let’s see the total monthly sales to get an idea of the scope.

select Month, round(sum(QuantityOrdered * PriceEach), 2) as MonthlySale 
from Sales_Data group by Month;

MonthMonthlySale
11822256.73
22202022.42
32807100.38
43390670.24
53152606.75
62577802.26
72647775.76
82244467.88
92097560.13
103736726.88
113199603.2
124613443.34

We see a general increasing trend in sales over time. This is a positive indicator for future prospects, and it instills confidence in stakeholders, fosters a positive perception among consumers.

We are interested in where the sales come from, so we determine the popularity of products by finding out their sale quantity.

select Product, sum(QuantityOrdered) as Quantity 
from Sales_Data group by Product order by Quantity desc;


ProductQuantity
AAA Batteries (4-pack)31017
AA Batteries (4-pack)27635
USB-C Charging Cable23975
Lightning Charging Cable23217
Wired Headphones20557
Apple Airpods Headphones15661
Bose SoundSport Headphones13457
27in FHD Monitor7550
iPhone6849
27in 4K Gaming Monitor6244
34in Ultrawide Monitor6199
Google Phone5532
Flatscreen TV4819
Macbook Pro Laptop4728
ThinkPad Laptop4130
20in Monitor4129
Vareebadd Phone2068
LG Washing Machine666
LG Dryer646

Batteries and charging cables contributed most to the sale quantities, which is not surprising, given that they are consumables and has relatively low price.

It’s also important to find out which products generated the highest revenue. This information could enable business to refine their product offerings, optimize marketing strategies, and focus resources on the most lucrative segments of their portfolio:

select Product, round(sum(QuantityOrdered * PriceEach), 2) as PerProductSale
from Sales_Data group by Product order by PerProductSale desc;

ProductPerProductSale
Macbook Pro Laptop8037600.0
iPhone4794300.0
ThinkPad Laptop4129958.7
Google Phone3319200.0
27in 4K Gaming Monitor2435097.56
34in Ultrawide Monitor2355558.01
Apple Airpods Headphones2349150.0
Flatscreen TV1445700.0
Bose SoundSport Headphones1345565.43
27in FHD Monitor1132424.5
Vareebadd Phone827200.0
20in Monitor454148.71
LG Washing Machine399600.0
LG Dryer387600.0
Lightning Charging Cable347094.15
USB-C Charging Cable286501.25
Wired Headphones246478.43
AA Batteries (4-pack)106118.4
AAA Batteries (4-pack)92740.83
Macbook Pro Laptop8037600.0

Laptops and smartphones emerged as the primary drivers of sales, with a noteworthy emphasis on Apple products, a trend that finds justification in their elevated unit prices.

This trend may or may not be true in different cities, we can add a filter to see sales specific to different cities (e.g. where city = ‘Dallas’) or list all cities:

select Product, City, round(sum(Sales),2) as PerProductSale
from Sales_Data
group by Product, City
order by City, PerProductSale desc;

ProductCityPerProductSale
Lightning Charging CableAtlanta28091.05
USB-C Charging CableAtlanta22884.25
Wired HeadphonesAtlanta18932.21
AA Batteries (4-pack)Atlanta8421.12

                                                               (this is a short sample due to size)

It helps to know peak hours:

select Hour, round(sum(Sales), 2) as SaleAmount from Sales_Data
group by Hour order by Hour+0 asc;

HourSaleAmount
0713721.27
1460866.88
2234851.44
3145757.89
4162661.01
5230679.82
6448113.0
7744854.12
81192348.97
91639030.58
101944286.77
112300610.24
122316821.34
132155389.8
142083672.73
151941549.6
161904601.31
172129361.61
182219348.3
192412938.54
202281716.24
212042000.86
221607549.21
231179304.44

Knowing the specific time periods when sales experience a surge can significantly inform sales strategies and resource allocation. Recognizing peak sales hours allows businesses to optimize staffing levels and target marketing efforts, which helps capitalize on increased customer engagement, leading to higher conversion rates and revenue generation.









Related Post