Balanced Tree Clothing Company prides themselves on providing an optimised range of clothing and lifestyle wear for the modern adventurer!
Danny, the CEO of this trendy fashion company has asked you to assist the team’s merchandising teams analyse their sales performance and generate a basic financial report to share with the wider business.
For this case study there is a total of 4 datasets for this case study - however you will only need to utilise 2 main tables to solve all of the regular questions, and the additional 2 tables are used only for the bonus challenge question!
balanced_tree.product_details includes all information about the entire range that Balanced Clothing sells in their store.
|c4a632||13||Navy Oversized Jeans - Womens||1||3||7||Womens||Jeans||Navy Oversized|
|e83aa3||32||Black Straight Jeans - Womens||1||3||8||Womens||Jeans||Black Straight|
|e31d39||10||Cream Relaxed Jeans - Womens||1||3||9||Womens||Jeans||Cream Relaxed|
|d5e9a6||23||Khaki Suit Jacket - Womens||1||4||10||Womens||Jacket||Khaki Suit|
|72f5d4||19||Indigo Rain Jacket - Womens||1||4||11||Womens||Jacket||Indigo Rain|
|9ec847||54||Grey Fashion Jacket - Womens||1||4||12||Womens||Jacket||Grey Fashion|
|5d267b||40||White Tee Shirt - Mens||2||5||13||Mens||Shirt||White Tee|
|c8d436||10||Teal Button Up Shirt - Mens||2||5||14||Mens||Shirt||Teal Button Up|
|2a2353||57||Blue Polo Shirt - Mens||2||5||15||Mens||Shirt||Blue Polo|
|f084eb||36||Navy Solid Socks - Mens||2||6||16||Mens||Socks||Navy Solid|
|b9a74d||17||White Striped Socks - Mens||2||6||17||Mens||Socks||White Striped|
|2feb6b||29||Pink Fluro Polkadot Socks - Mens||2||6||18||Mens||Socks||Pink Fluro Polkadot|
balanced_tree.sales contains product level information for all the transactions made for Balanced Tree including quantity, price, percentage discount, member status, a transaction ID and also the transaction timestamp.
Product Hierarcy & Product Price
Thes tables are used only for the bonus question where we will use them to recreate the
|14||5||Teal Button Up||Style|
|18||6||Pink Fluro Polkadot||Style|
Interactive SQL Instance
You can use the embedded DB Fiddle below to easily access these example datasets - this interactive session has everything you need to start solving these questions using SQL.
You can click on the
Edit on DB Fiddle link on the top right hand corner of the embedded session below and it will take you to a fully functional SQL editor where you can write your own queries to analyse the data.
You can feel free to choose any SQL dialect you’d like to use, the existing Fiddle is using PostgreSQL 13 as default.
Serious SQL students will have access to the same relevant schema SQL and example solutions which they can use with their Docker setup from within the course player!
Case Study Questions
The following questions can be considered key business questions and metrics that the Balanced Tree team requires for their monthly reports.
Each question can be answered using a single query - but as you are writing the SQL to solve each individual problem, keep in mind how you would generate all of these metrics in a single SQL script which the Balanced Tree team can run each month.
High Level Sales Analysis
- What was the total quantity sold for all products?
- What is the total generated revenue for all products before discounts?
- What was the total discount amount for all products?
- How many unique transactions were there?
- What is the average unique products purchased in each transaction?
- What are the 25th, 50th and 75th percentile values for the revenue per transaction?
- What is the average discount value per transaction?
- What is the percentage split of all transactions for members vs non-members?
- What is the average revenue for member transactions and non-member transactions?
- What are the top 3 products by total revenue before discount?
- What is the total quantity, revenue and discount for each segment?
- What is the top selling product for each segment?
- What is the total quantity, revenue and discount for each category?
- What is the top selling product for each category?
- What is the percentage split of revenue by product for each segment?
- What is the percentage split of revenue by segment for each category?
- What is the percentage split of total revenue by category?
- What is the total transaction “penetration” for each product? (hint: penetration = number of transactions where at least 1 quantity of a product was purchased divided by total number of transactions)
- What is the most common combination of at least 1 quantity of any 3 products in a 1 single transaction?
Write a single SQL script that combines all of the previous questions into a scheduled report that the Balanced Tree team can run at the beginning of each month to calculate the previous month’s values.
Imagine that the Chief Financial Officer (which is also Danny) has asked for all of these questions at the end of every month.
He first wants you to generate the data for January only - but then he also wants you to demonstrate that you can easily run the samne analysis for February without many changes (if at all).
Feel free to split up your final outputs into as many tables as you need - but be sure to explicitly reference which table outputs relate to which question for full marks :)
Use a single SQL query to transform the
product_prices datasets to the
Hint: you may want to consider using a recursive CTE to solve this problem!
Sales, transactions and product exposure is always going to be a main objective for many data analysts and data scientists when working within a company that sells some type of product - Spoiler alert: nearly all companies will sell products!
Being able to navigate your way around a product hierarchy and understand the different levels of the structures as well as being able to join these details to sales related datasets will be super valuable for anyone wanting to work within a financial, customer or exploratory analytics capacity.
Hopefully these questions helped provide some exposure to the type of analysis we perform daily in these sorts of roles!
If you’d like to see the official code solutions and explanations for this case study and a whole lot more, please consider joining me for the Serious SQL course - you’ll get access to all course materials and I’m on hand to answer all of your additional SQL questions directly!
Serious SQL students get access to complete solutions for each case study, the solutions will be made available inside the 8 Week SQL Challenge section of the course player as soon as they are ready!
Serious SQL is currently on sale for $29 and $19 for students from the standard price of $39 and $29, but only for a limited time so don’t miss out!
This section will be updated in the future with any community member solutions with a link to their respective GitHub repos!
If you found any of these 8 Week SQL Challenge case studies helpful or valuable - please consider supporting me on Ko-fi!
The 8 Week SQL Challenge is proudly brought to you Danny Ma and the Data With Danny virtual data apprenticeship program.
If you would like to contribute to the 8 Week SQL Challenge website or volunteer as a data community mentor - please get in touch with me anytime. I always enjoy meeting amazing people who have the same drive and motivation to help others!
You can reach me directly in the official Slack Channel or find me on social media:
From your friendly data mentor, Danny :)