0% found this document useful (0 votes)
82 views17 pages

8 Weeks SQL Challenge. by Omojuwa Oluwaseun by Omojuwa Oluwaseun May, 2023 Medium

The document summarizes an 8-week SQL challenge where the author was tasked with answering business questions to help a restaurant owner analyze customer data and improve their business. The author provides solutions to 10 questions about customers' purchase amounts, visit frequency, favorite menu items, and loyalty program data. Key insights include which menu item was most popular and purchase amounts for members before joining the loyalty program.

Uploaded by

shmasood55
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)
82 views17 pages

8 Weeks SQL Challenge. by Omojuwa Oluwaseun by Omojuwa Oluwaseun May, 2023 Medium

The document summarizes an 8-week SQL challenge where the author was tasked with answering business questions to help a restaurant owner analyze customer data and improve their business. The author provides solutions to 10 questions about customers' purchase amounts, visit frequency, favorite menu items, and loyalty program data. Key insights include which menu item was most popular and purchase amounts for members before joining the loyalty program.

Uploaded by

shmasood55
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/ 17

8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

Search Medium

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

8 Weeks Sql Challenge


Omojuwa Oluwaseun · Follow
7 min read · May 3

Listen Share

By: Omojuwa Oluwaseun

1 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Introduction

I recently decided to challenge myself and participate in the 8-week sql challenge
hosted by Danny Ma. For the first case we were tasked with some business questions
that could help provide insights into the restaurant business that will help make
recommendations needed to grow

Danny seriously loves Japanese food so in the beginning of 2021, he decides to

2 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

embark upon a risky venture and opens up a cute little restaurant that sells his 3
favourite foods: sushi, curry and ramen. His Diner is in need of assistance to help
You are signed out. Sign in with your member account
the restaurant(sh__@g__.com)
stay afloat —tothe restaurant
view has captured
other member-only some
stories. Sign in very basic data from
their few months of operation but have no idea how to use their data to help them
run the business.

Problem Statement

Danny wants to use the data to answer a few simple questions about his customers,
especially about their visiting patterns, how much money they’ve spent and also
which menu items are their favourite. Having this deeper connection with his
customers will help him deliver a better and more personalized experience for his
loyal customers.

He plans on using these insights to help him decide whether he should expand the
existing customer loyalty program — additionally he needs help to generate some
basic datasets so his team can easily inspect the data without needing to use SQL.

Danny has provided you with a sample of his overall customer data due to privacy
issues and has shared 3 key datasets for this case study: Sales, Menu, Members

Case Study Questions

1. What is the total amount each customer spent at the restaurant?

2. How many days has each customer visited the restaurant?

3. What was the first item from the menu purchased by each customer?

4. What is the most purchased item on the menu and how many times was it
purchased by all customers?

5. Which item was the most popular for each customer?

6. Which item was purchased first by the customer after they became a member?

7. Which item was purchased just before the customer became a member?

8. What is the total items and amount spent for each member before they became

3 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

a member?

9. If each $1 You are signed out. Sign in with your member account
spent equates to 10 points and sushi has a 2x points multiplier — how
(sh__@g__.com) to view other member-only stories. Sign in
many points would each customer have?

10. In the first week after a customer joins the program (including their join date)
they earn 2x points on all items, not just sushi — how many points do customer
A and B have at the end of January?

Solutions

1. To solve this question, I joined the sales and menu table, the customer id was
selected and the aggregate of the amount they spent was also selected using the
sum function.

Answer: Customer A spent $76, Customer B spent $74 while Customer C spent $36

2. To do this, I selected the customer id, and the count of their unique order dates,
the distinct function here is to enable us choose the unique number of times they
visited the restaurant

4 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Answer: Customer A visited the restaurant 4 times while customer B a total of 6


times and Customer C had a total of 2 times.

3. To solve this, CTE was created to rank each customer’s order, so that older dates
had rank 1 and earlier dates had higher ranks. After which I joined the CTE to the
menu table, using product_id , and filtered the result to return records with only 1
as the rank.

5 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Answer: Customer A’s first item ordered were Sushi & Curry, customer B’s first item
ordered was Curry, while customer C’s first item ordered was Ramen.

4. To do this, I used the count function and also aggregated it by product name to
allow us see how many times each product were bought. The limit function was set
to 1 to return only the item with the highest purchase

6 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Answer: the product with the highest purchase by all customers is Ramen and it was
purchased 8 times.

5. To know the most popular items, we need to have an idea of how many times a
customer purchased an item. to do this, a CTE was created with the customer-id,
product_name and count of each product, the Rank windows function was also used
to rank the count of products from highest to lowest. I also filtered it to return result
with ranks that only have 1

7 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Answer: Ramen was the most popular item for customer A with 1 count. Sushi,
curry, and Ramen had equal number of times they were purchased for customer B
with 2 each. Ramen was the most popular item for customer C with 3 counts.

7. To answer this question, I used a Common Table Expression (CTE) to join the
sales and menu tables. I then used the MAX function to extract the latest order date
for each customer. After which I filtered the results to only include orders made by
each customer just before they joined the member's loyalty program.

8 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Answer: Customer A ordered Sushi and Curry just before they joined the
membership, while Customer B ordered Sushi

8. To address this question, I performed a join on the three tables and utilized the
COUNT function to determine the number of times each customer made a
purchase, as well as the SUM function to calculate the total cost of each customer’s
purchases. After which I applied a WHERE clause to limit the results to purchases
made before the customer joined the loyalty program.

9 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Answer: Customer A bought a total of two items where they spent $25 while
Customer B bought a total of three items and spent $40 before they joined.

9. To solve this challenging question, I utilized the CASE statement to categorize and
group the points earned by customers based on their purchases of sushi and other
items. This statement was used to create a new column called ‘points’ that showed
the total points earned by each customer, based on the conditions set in the CASE
statement. Additionally, I joined the sales and menu tables using the common
primary key (product_id) to extract the products purchased, the amount spent on
each product, and the total points earned by each customer.

10 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Follow

Written by Omojuwa Oluwaseun


4 Followers

I am a Data enthusiast willing to collaborate and work on projects. I work with various tools like Excel, MySql
and PowerBi

More from Omojuwa Oluwaseun

Answer: Customer A had a total point of 860, Customer B had a total point of 940,
while customer C had a total point of 360.

Bonus Question:

The following questions are related creating basic data tables that Danny and his
team can use to quickly derive insights without needing to join the underlying tables
using SQL.
Omojuwa Oluwaseun

Recreate the tableAnalysis


Titanic Survival with: customer_id , order_date , product_name , price , member

(Y/N)
Introduction

5 min read · Apr 23

26

11 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Omojuwa Oluwaseun

CLEANING THE FIFA-2021 DATASET WITH POWER QUERY


As is common knowledge, data cleaning is one of the essential skills a data analyst should
possess. This challenge was hosted in the data…

5 min read · Mar 30


Insights
26 the analysis, I discovered a few interesting things that would be certainly
From
useful for Danny.

• Customer B is the most frequent visitor with 6 visits in Jan 2021.


See all from Omojuwa Oluwaseun

• Danny’s Diner’s most popular item is ramen.

• Customer A and C loves ramen whereas Customer B seems to enjoy sushi, curry
and ramen equally.

• Customer A is the 1st member of Danny’s Diner and his first order is curry.

Recommended from Medium


• Before they became members, Customer A and Customer B spent $25 and $40
respectively.

• Throughout Jan 2021, Customer A, Customer B and Customer C had 860 points,

12 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

940 points and Customer C: 360 points respectively.

You are signed out. Sign in with your member account


Completing this project was a huge and challenging task, but it marks just the
(sh__@g__.com) to view other member-only stories. Sign in
beginning of our journey. I am committed to completing many more projects and
tasks in the future, and with each one, will continue to grow and improve our skills.

Feel free to share your opinion about my analysis in the comments. Suggestions on
how to optimize my SQL code for performance are also welcome.

#sql_analysis #data_analysis #data

The PyCoach in Artificial Corner

You’re Using ChatGPT Wrong! Here’s How to Be Ahead of 99% of ChatGPT


Users
Master ChatGPT by learning prompt engineering.

· 7 min read · Mar 17

17.9K 325

13 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Scott H. Young

10 Best Ways To Use ChatGPT (With Examples)


Tips on how maximize your work and school performance with the latest AI tool.

· 10 min read · 5 days ago

1K 18

Lists

Staff Picks
300 stories · 59 saves

Stories to Help You Level-Up at Work


19 stories · 13 saves

Self-Improvement 101
20 stories · 24 saves

Productivity 101
20 stories · 33 saves

14 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

Christina Sa in UX Planet

The UX Design Case Study That Got Me Hired


Getting a job in UX design is tough, but one particular case study helped me stand out from the
crowd. I designed a non-traditional…

· 8 min read · Mar 16

3.8K 47

15 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

Alex Mathers

14 things I wish I knew


You are at 25
signed out. Sign(now
in with that I’m 38)
your member account
(sh__@g__.com) to view other member-only stories. Sign in
I’m writing soon after my 38th birthday. It’s a time to reflect.

· 4 min read · Dec 27, 2022

10.8K 196

Andrew Courter in Level Up Coding

Is Star Schema Dead?


Star schema has been used in data warehouses and data marts for decades now. With storage
getting cheaper is it time to move on?

· 3 min read · Jan 2

132 6

16 of 17 5/13/2023, 8:35 AM
8 Weeks Sql Challenge. By: Omojuwa Oluwaseun | by Omojuwa Oluw... https://medium.com/@omojuwa_oluwaseun/8-weeks-sql-challenge-7cd...

You are signed out. Sign in with your member account


(sh__@g__.com) to view other member-only stories. Sign in

HKN MZ in Towards Dev

Most Usefull Queries for Sql Server


In this article, I try to add almost all usefull sql queries to get fast results. And this article will be
updated time by time.

· 7 min read · Nov 13, 2022

121 2

See more recommendations

17 of 17 5/13/2023, 8:35 AM

You might also like