<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mark Mukasa on Medium]]></title>
        <description><![CDATA[Stories by Mark Mukasa on Medium]]></description>
        <link>https://medium.com/@macmukasa?source=rss-e04af16a55e0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZXMuHRxjZwS9YqWHeZu7BA.jpeg</url>
            <title>Stories by Mark Mukasa on Medium</title>
            <link>https://medium.com/@macmukasa?source=rss-e04af16a55e0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:59:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@macmukasa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Google Data Analytics Course Capstone Project 1]]></title>
            <link>https://medium.com/@macmukasa/google-data-analytics-course-capstone-project-1-f2f4e82a2dac?source=rss-e04af16a55e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2f4e82a2dac</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[tableau]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[projects]]></category>
            <dc:creator><![CDATA[Mark Mukasa]]></dc:creator>
            <pubDate>Mon, 21 Mar 2022 09:49:14 GMT</pubDate>
            <atom:updated>2022-03-21T09:49:14.992Z</atom:updated>
            <content:encoded><![CDATA[<h3>Google Data Analytics Course Capstone Project</h3><p>Case Study 1: Cyclistic Bike Sharing</p><p>I’ve recently been undertaking the Google Data Analytics Professional Certificate course on Coursera. I successfully completed the course which contained 8 different courses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*nQlX78Ksy8gmgTq8Ya-ySw.png" /><figcaption><a href="https://www.credly.com/badges/34ef6ae2-b1a1-4e73-ac3d-107a09b71400/public_url">Credly certitifaction badge</a></figcaption></figure><p>As part of the course, we were exposed to the complete Data Analysis process, right from the ASK phase, to the last, the ACT phase. We learned to use data analysis tools like SQL, Spreadsheets(Microsoft Excel and Google Sheets), R, and Tableau for visualisations.</p><p>Students were required to complete a case study to showcase the skills gained throughout the course. This is my attempt at Case Study 1.</p><h4>Introduction</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*3HuGKv8K2sVUmTGptE__FA.png" /></figure><p>In 2016, Cyclistic launched a successful bike-share program, which has grown to a fleet of 5,824 bicycles that are geo-tracked and locked into a network of 692 stations across Chicago. The bikes can be unlocked from one station and returned to any other station in the system anytime. The business has flexible pricing plans: single-ride passes, full-day passes, and annual memberships. Customers who purchase annual memberships are referred to as Cyclistic members, and those that purchase single-ride or full-day passes are referred to as casual riders.</p><p>I assume the position of Junior data analyst working in the marketing team at Cyclistic. The team wants to understand how casual riders and annual members use Cyclistic bikes differently, in order to design a new marketing strategy to convert casual riders into annual members.</p><h4>Business Task</h4><p>Utilise Cyclistic’s historical bike trip data to derive analysis to understand the usage trends and behaviours of the 2 customer segments.</p><h4>Data Source and preparation</h4><p>The data was collected by Cyclistic (hence original &amp; reliable) and is stored in the company’s database as zipped CSV files. The data has been made available by Motivate International Inc. under this <a href="https://ride.divvybikes.com/data-license-agreement">license</a>.</p><p>I downloaded the 2021 data as 12 zipped files, containing data for each month. I extracted the different CSV files into a folder and used <a href="https://www.rstudio.com/">RStudio</a> to carry out data preparation and exploration. I did this because R’s ability to handle large datasets, as opposed to say, Microsoft Excel.</p><p>First, I loaded the required packages for data manipulation; <em>tidyverse</em>, <em>janitor</em>, <em>skimr</em>, <em>lubridate</em> and <em>stringr</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*jfAzVAWxPjEFwrwUUtoaJw.png" /></figure><h4>Data importation and merging</h4><p>I imported the different CSV files into R using the <em>read_csv()</em> function.</p><p>Using the head() function I realised that the column names are all in harmony for all the 12 CSV files. I went on to merge the datasets using the <em>bind_rows()</em> function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l6-ehvQR5bLQct2E3osO-Q.png" /></figure><p>To understand the structure and shape of the dataset, I used the <em>glimpse()</em> function to return the summary below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7o2Fq5HUA1aFvts30zHhhA.png" /></figure><p>The dataset has a 5,595,063 rows of data, each representing a trip, with 13 columns, each representing a variable about the trip.</p><h4>Data Cleaning</h4><p>Before analysis, I had to prepare the data to ensure that the data is clean, and devoid of any redundancies. The data cleaning process included the following;</p><ul><li><strong>Removing white space in the start- and end-station names</strong>. I used the <em>str_trim()</em> function as shown below;</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dE91NPqKH7VwfZlgKOjDYw.png" /></figure><ul><li><strong>Harmonising the <em>rideable_type</em> column</strong>. I realised that this column shows the type of bike used; docked, classic &amp; electric. Since classics bikes were previously labelled docked bikes, they refer to the same thing. I changed the instances of docked bikes to classic bikes using the <em>str_replace()</em> function and counted them using the <em>count()</em> function.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E0FT3O_9plHKwMpyU9XgOw.png" /></figure><ul><li><strong>Removing redundant data</strong>. Unlike electric bikes, all classic bikes must have a start and end-station name where they are docked. Using the <em>filter()</em> function, I removed all rows where classic bikes were used, but with missing start- or end-station names. The resulting dataset had 5,585,729 rows.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LSeshLWBuddjWWRsaWqwvg.png" /></figure><h4>Data transformation &amp; further cleaning</h4><ul><li>For this part, I created new columns from the existing ones that would enable me analyse the data effectively. From the <em>started_at</em> column, I created <em>month</em>, <em>hour_of_day</em>, <em>ride_duration_hrs</em>, <em>ride_duration_mins</em> columns, and <em>route</em> column, which showed the combination of start_station and end_station names. The resulting dataset had 19 columns.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*atY07V2Ox1Bl_WJC5FG-EQ.png" /></figure><ul><li>For data integrity, I removed all rows containing trips that were longer than a day or shorter than 1 minute. The resulting dataframe had 5,498,575 rows.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nMbhC6eaI9BRkdbB6hp30g.png" /></figure><p>This marked the end of the data cleaning. I exported the dataset into a CSV file using the <em>write_csv()</em> function, to be used for analysis in <a href="https://public.tableau.com/en-us/s/">Tableau</a>.</p><h4>Data Analysis</h4><p><strong>Annual Breakdown</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kkxf8CVgYnvFTiK5kaJB0A.png" /></figure><p>Over the course of 2021, members took 3.01M rides as compared to casual riders who took 2.49M rides.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bbIr7ePQbxeI1-zhMu3ngg.png" /></figure><p>Classic bikes were preferred over electric bikes largely across 2021. However, in November and December there was an uptake of electric bikes as compared to classic bikes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eewzzDe6nnporYmW0arZrA.png" /></figure><p>From the above graph, we see the trend of ride count by month. Customers order the most rides between June and September, and the ride counts are lowest between December and Feb. This coincides with seasonal changes. Winter months register the lowest ride counts, and summer months register the highest ride counts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EaQXcKsEyijbazyM9DUcgQ.png" /></figure><p>When segmented by Customer type, over the course of the year, rides made by members largely outnumber those by casual riders. Towards the summer months however, casual rides outnumber member rides. Following the trend, casual rides hit lows around the winter months (December to February). To further explore this, I created a field to account for seasons, where;</p><ul><li>Winter: December, January, February</li><li>Spring: March, April, May</li><li>Summer: June, July, August</li><li>Autumn: September, October, November</li></ul><p>This resulted in the chart below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GyJZTCftim9tLqGRITFdtQ.png" /></figure><p>Across all seasons, member rides outnumbered casual rides except for Summer months, where casual rides amounted to 1.21M compared to member rides at 1.1M. From this, it can be hypothesized that casual riders are usually tourists, who use Cyclistic bikes for leisure, during the warmer, summer months.</p><p><strong>Distribution of rides by day of the week</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*qHzvU0YNvTRSMy95kEgdEg.png" /></figure><p>From the graph above, wee can see that Saturday is the most popular day, followed by Sunday. Monday is the least popular.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WYe5eDJt2MFCdf5GqwoqMA.png" /></figure><p>Going further, it is evident that members take more rides during the work-week(Monday to Friday), as compared to casual riders. Similarly, casual riders take more rides over the weekend as compared to members.</p><p>To investigate this further, let’s see the trend over seasons:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wFWlzBsF469N00ghraZVXA.png" /></figure><p>The trend still persists for Spring, Summer and Autumn months. However, there is a drastic change in Winter, where the ride count remains low for casual riders even on the weekends.</p><p><strong>Ride Duration</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*dRvsDVPwyvffqQ3XNF1Yqw.png" /></figure><p>The average ride duration varies from by day, with Sunday have the highest duration at 24mins, followed by Saturday with 23 Mins. The week days all are below the weekly average of 20 mins. It can be deduced that riders love to ride longer on the weekends. Let’s see how this varies by customer type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*UU387basLQABEqu52yu_Qg.png" /></figure><p>On average, members ride for shorter distances when compared to casual riders, whose average ride duration is almost twice that of members. Sundays have the highest average ride duration for both members and casual riders. Is this consistent over all seasons?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nKcfq8zqyNWEDdG8CDFm2A.png" /></figure><p>On average, spring months have the highest ride duration, followed by summer, autumn, and winter has the shortest ride duration. This seems to be consistent with activity across the seasons; Due to the cold, people tend to choose to stay indoors and only take rides only when necessary, which accounts for the short trips. On the other hand, for warmer seasons, customers tend to ride the bikes longer as its more conducive. Customers tend to have longer trips on Sundays over the summer, autumn, and fall. However, during winter, Saturdays are preferred.</p><p><strong>Preferred ride start time</strong></p><p>Here, we’ll look at the ride count across different trip start times. I decided to split this analysis into;</p><ul><li>Weekend start times over Seasons</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9p4TVNIt1DReclPvFZxkBQ.png" /></figure><p>As seen from the graph above, the most popular start time for casual rides is during Summer weekends at 1 PM, where as for members it’s summer weekends at noon. Generally, across all seasons, the most popular weekend ride start time period is noon to 5PM.</p><ul><li>Weekday start times over Seasons</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z6AjsSlYHRVKIPlAs2tdnw.png" /></figure><p>For week days(Mon-Fri), we see 3 peaks, one at 8 AM, the second at noon, and the third at 5 PM for the members. For casual rides, we see a gradual increase in ride counts from 8AM to 5PM, with 5PM having the highest ride count.</p><h4>Most Popular start- and end-stations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0mm-3Dlbuv_x16Dg4pLIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irqZqZOOLxybXVsljo1fAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tmp9GVrIEE9O2brMxFj4sQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xsXfU2jQ9-XaGiyd5Fzelg.png" /></figure><h4>Summary of Insights</h4><p>Based on my analysis, here’s what I can deduce about the behaviour of Cyclistic customers.</p><p><strong>Members</strong></p><ul><li>Average 3.2K rides per day in winter(lowest) to 12K rides per day in Summer. Annual average is 8.2K rides per day. On weekdays, the average number of trips per day is 8.5K, as opposed to 7.6K rides per day over the weekends.</li><li>73.65% of rides occur during the week (Mon-Fri).</li><li>Members have an average ride duration of 13 mins. It’s highest in Summer(14.22 mins) and lowest in Autumn (12.29 mins). On weekends, the average ride duration is 15 mins, and 12.81 mins on weekdays.</li><li>Most popular commute times: 8AM, 12PM and 5PM on the weekdays. over the weekends, the most popular commute time is between 12PM and 3PM.</li><li>Most used dock station(pickup — drop off) route:<br><em>Ellis Ave &amp; 60th St — Ellis Ave &amp; 55th St.</em></li></ul><p>From the analysis, members most likely use Cyclistic bikes for their Home-Work commutes. This is explained by the average ride counts on weekdays, and the peak ride start times, which correspond to the morning (8AM) work commute, and the evening (5PM) home commute. The average ride duration is almost constant over the course of the week.</p><p><strong>Casual Riders</strong></p><ul><li>Average 1K rides per day in winter(lowest) to 13K rides per day in Summer(highest). Annual average is 6.8K rides per day. On weekdays, the average number of trips per day is 5.6K, as opposed to 9.8K rides per day over the weekends.</li><li>59% of rides occur during the week (Mon-Fri).</li><li>Casual riders have an average ride duration of 24.79 mins. It’s highest in spring (28.13 mins) and lowest in Autumn (20.97 mins). On weekends, the average ride duration is 28.40 mins, and 23.35 mins on weekdays.</li><li>Most popular commute times: 5PM on the weekdays. Over the weekends, the most popular commute time is between 11AM and 3PM.</li><li>Most used dock station(pickup — drop off) route:<br><em>Streeter Dr &amp; Grand Ave — Streeter Dr &amp; Grand Ave</em></li></ul><p>From the analysis, the average casual rider uses Cyclistic bikes for leisure/ fitness purposes. This is supported by the fact that the highest ride count occurs in the summer months during the summer holidays, with little activity in the winter months. In addition, the highest ride counts occur over the weekend (Saturday &amp; Sunday), with an average ride duration almost twice that of members.</p><h4>Recommendations</h4><p>Now that we know the usage habits of casual riders, I’d suggest the following recommendations to the marketing team.</p><ul><li>Design a new annual membership plan targeting fitness and wellness enthusiasts. Ideally, this plan should aim to maximise bike usage by providing access to customers during the weekdays from 5PM, and weekends.</li><li>To further target that select group, Cyclistic could establish partnerships with companies in the wellness and fitness industry to provide this new offering to their customers.</li><li>In order to reach the already existing casual riders, marketing campaigns should be launched at the most popular stations in the spring &amp; run throughout the summer months, especially on the weekends to draw the attention of casual riders to the new offering.</li></ul><p><strong>Thank you for reading! Happy to receive your suggestions and recommendations.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2f4e82a2dac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[8 Week SQL Challenge: Case Study #1 — Danny’s Diner]]></title>
            <link>https://medium.com/@macmukasa/8-week-sql-challenge-case-study-1-dannys-diner-325d05cef679?source=rss-e04af16a55e0------2</link>
            <guid isPermaLink="false">https://medium.com/p/325d05cef679</guid>
            <dc:creator><![CDATA[Mark Mukasa]]></dc:creator>
            <pubDate>Mon, 28 Feb 2022 10:13:12 GMT</pubDate>
            <atom:updated>2022-02-28T10:13:12.098Z</atom:updated>
            <content:encoded><![CDATA[<h3>8 Week SQL Challenge: Case Study #1 — Danny’s Diner</h3><h4>Using postgreSQL to query databases and answer business questions</h4><p>I decided to participate in the 8 week SQL challenge. You may find the challenge details <a href="https://8weeksqlchallenge.com/">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZf3OcTCpirBd6W0LFA89w.png" /><figcaption>Danny’s Diner Poster</figcaption></figure><h4>Introduction</h4><p>Danny seriously loves Japanese food so in the beginning of 2021, he decides to embark upon a risky venture and opens up a cute little restaurant that sells his 3 favourite foods: sushi, curry and ramen.</p><p>Danny’s Diner is in need of your assistance to help the restaurant stay afloat — the restaurant has captured some very basic data from their few months of operation but have no idea how to use their data to help them run the business.</p><h4>Problem Statement</h4><p>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 personalised experience for his loyal customers.</p><p>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.</p><p>Danny has provided you with a sample of his overall customer data due to privacy issues — but he hopes that these examples are enough for you to write fully functioning SQL queries to help him answer his questions!</p><p>Danny has shared with you 3 key datasets for this case study:</p><ul><li>sales</li><li>menu</li><li>members</li></ul><p>The Entity Relationship Diagram is shown here below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gmA77V-808G1MakX6V2nw.png" /><figcaption>Entity Relationship Diagram</figcaption></figure><h4>Case Study Questions</h4><ol><li>What is the total amount each customer spent at the restaurant?</li><li>How many days has each customer visited the restaurant?</li><li>What was the first item from the menu purchased by each customer?</li><li>What is the most purchased item on the menu and how many times was it purchased by all customers?</li><li>Which item was the most popular for each customer?</li><li>Which item was purchased first by the customer after they became a member?</li><li>Which item was purchased just before the customer became a member?</li><li>What is the total items and amount spent for each member before they became a member?</li><li>If each $1 spent equates to 10 points and sushi has a 2x points multiplier — how many points would each customer have?</li><li>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?</li></ol><h4>Solution</h4><p>I chose to query the data using postgreSQL on my windows laptop. To do this, I created a database called dannys_diner and used to scripts provided on the challenge webpage <a href="https://8weeksqlchallenge.com/case-study-1/">here</a>.</p><p>On investigating the database, no data cleaning/ transformation is required, so I proceeded to answer the case study questions.</p><ol><li><strong>What is the total amount each customer spent at the restaurant?</strong></li></ol><p>This required using the JOIN STATEMENT to join the menu and sales tables, then utilising the SUM function on the price column, grouping by the customer_id.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*bqWoz-eFkm9ML1eT1Jf7LA.png" /><figcaption>Question 1 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*RoPNpC3dTXZPAF84cq4lNw.png" /><figcaption>Question 1 query result</figcaption></figure><p>Total amount spent;</p><ul><li>Customer A spent $76</li><li>Customer B spent $74</li><li>Customer C spent $36</li></ul><p>2.<strong> How many days has each customer visited the restaurant?</strong></p><p>I determined this using the order_date column in the sales table. To avoid repetitive counting of multiple visits on a single day, I used the COUNT DISTINCT function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ienYlWkC-k4RE0RVshKdQ.png" /><figcaption>Question 2 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*n_ogHoFha2ND9PgUHxa4Cw.png" /><figcaption>Question 2 query result</figcaption></figure><p>Customer B had the most visits (6), followed by customer A with 4 visits and customer C with just 2 visits.</p><p>3. <strong>What was the first item from the menu purchased by each customer?</strong></p><p>For this question, I used DENSE_RANK to rank the orders by the order_date column for each customer to create a temporary table ranked_date. The required window is PARTITION BY customer_id ORDER BY order_date. From the ranked_date table, since we only want the very first order, I filtered the results for rank = 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4kWVEVGAuIr1wWXfxquDjw.png" /><figcaption>Question 3 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcNAIRwGtgABL_7LbVD44w.png" /><figcaption>Question 3 query result</figcaption></figure><ul><li>Customer A’s first order was curry and sushi</li><li>Customer B’s first order was curry</li><li>Customer C’s first order was ramen.</li></ul><p>4. <strong>What is the most purchased item on the menu and how many times was it purchased by all customers?</strong></p><p>To answer this question, I joined the menu and sales tables, then counted the product_id from the sales table, grouping by the product_name. I ordered the resulting table by descending count. Since only the most purchased item was required, I limited the results to only show the first row.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sGcCP2LwLxcQQZaPCrsEfQ.png" /><figcaption>Question 4 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*6f0430VgJNZiMwJv8i4liA.png" /><figcaption>Question 4 query result</figcaption></figure><p>5. <strong>Which item was the most popular for each customer?</strong></p><p>For each customer, I aggregated by count the product_id and used DENSE_RANK to rank the counts by descending order. Since we wanted the most popular item, I filtered for rank = 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ReivUYR8VvKlCMSRhR7B3A.png" /><figcaption>Question 5 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lZh7SHHYlp0pNFg4XTZehg.png" /><figcaption>Question 5 query result</figcaption></figure><ul><li>Customer A’s most popular item was ramen, bought thrice.</li><li>Customer B’s most popular items were sushi, curry &amp; ramen, all bought twice.</li><li>Customer C’s most popular item on the menu was ramen, bought thrice.</li></ul><p>6. <strong>Which item was purchased first by the customer after they became a member?</strong></p><p>For this question, I joined all the tables, used DENSE_RANK to rank the orders by the order_date. To get orders that occurred after the join_date, I filtered for order_date ≥ join_date. The resulting table was then filtered for date_rank =1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ehv2dMubRtYL8-c7gOr8iw.png" /><figcaption>Question 6 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIzvb3wfdJ5g3kRIb6CULQ.png" /><figcaption>Question 6 query result</figcaption></figure><ul><li>Customer A’s first order after joining was curry.</li><li>Customer B’s first order after joining was sushi.</li><li>Customer C didn’t become a member.</li></ul><p>7. <strong>Which item was purchased just before the customer became a member?</strong></p><p>The approach is similar to the previous question. However, for this one, I filtered the tables for only order_date &lt; join_date. In the desired window, I ordered the order_date in descending order, so the latest order would have a rank of 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iuAfZTxtgtmbbVYSW3F5Eg.png" /><figcaption>Question 7 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZciEqh3nz2WevhalacxllA.png" /><figcaption>Question 7 query result</figcaption></figure><ul><li>Customer A last purchased sushi and curry before becoming a member.</li><li>Customer B last purchased sushi before becoming a member.</li></ul><p>8. <strong>What is the total items and amount spent for each member before they became a member?</strong></p><p>Here, for each customer, I counted the product_id and aggregated by summing the price to get the total amount spent. I then filtered for order_date &lt; join_date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXCNbw_P3xYJ2fNIzrcw3Q.png" /><figcaption>Question 8 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8BmURCwdpk1mg2xoKZV0WA.png" /><figcaption>Question 8 query result</figcaption></figure><p>9. <strong>If each $1 spent equates to 10 points and sushi has a 2x points multiplier — how many points would each customer have?</strong></p><p>Here, I used the CASE STATEMENT to create a table including a column points<em>, </em>where sushi is assigned 20 points and 10 points for any other product. I then summed the points column for each customer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0yZ63U96XrMaGv-1KWyKA.png" /><figcaption>Question 9 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*nYSwSw8dNMAI8tDaPN0fbQ.png" /><figcaption>Question 9 query result</figcaption></figure><ul><li>Customer B has 940 points</li><li>Customer A has 860 points</li><li>Customer C has 360 points.</li></ul><p>10. <strong>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?</strong></p><p>For this question, I had to use multiple temporary tables. In the first temp table, I created a column one_week_later to show the date within which the 2X points are gained. Next, I used a CASE statement to calculate the points<em> </em>column<em> </em>showing points<em> </em>gained during the promo period by multiplying the price by 20, whereas all purchases made outside this window have the x10 multiplier. Finally, I summed up the points for each customer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnddugxnBT5W6wPiUl8hQw.png" /><figcaption>Question 10 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*ZIES5X19cgAJLFkIuJYDhw.png" /><figcaption>Question 10 query result</figcaption></figure><p>At the end of January,</p><ul><li>Customer A had 1270 points</li><li>Customer B had 720 points.</li></ul><h4>Bonus Questions</h4><p><strong>Join all the things to show a table using the available data showing </strong><strong>customer_id, </strong><strong>order_date, </strong><strong>product_name, </strong><strong>price, </strong><strong>member.</strong></p><p>This required joining all the tables followed by using a CASE statement to create the member column. We had to use a LEFT JOIN on sales and members tables because we didn’t want to exclude customer C who didn’t have a corresponding id in the members table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vcJsTbVaSZ5yWcY_OwKMwA.png" /><figcaption>Bonus question 1 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qPaSLChOkD-IF51L8k2V9A.png" /><figcaption>Bonus question 1 query result</figcaption></figure><p><strong>Danny also requires further information about the </strong><strong>ranking of customer products, but he purposely does not need the ranking for non-member purchases so he expects null </strong><strong>ranking values for the records when customers are not yet part of the loyalty program.</strong></p><p>With the previous table as join_cte, I used the CASE statement to create a column ranking, where for each customer, orders are ranked basing on the condition that they are members.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-0ljhDXSaW5dXS9V2__eA.png" /><figcaption>Bonus question 2 query</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4yFNfmpNjQtkpzF4rr6gtw.png" /><figcaption>Bonus question 2 query result</figcaption></figure><h4>Conclusions</h4><p>From this analysis, I was able to determine and answer questions posed by Danny’s Diner. Insights from this analysis include;</p><ul><li>Customer A spent the most money ($76) during this period, followed by Customer B ($74) and Customer C ($36). However, Customer B had the most visits to the Diner, followed by Customer A.</li><li>The most popular item on the menu is ramen, which was purchased 8 times.</li></ul><p>Please leave your feedback in the comment section below.</p><p>Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=325d05cef679" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>