<?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  Diana Injelwa on Medium]]></title>
        <description><![CDATA[Stories by  Diana Injelwa on Medium]]></description>
        <link>https://medium.com/@dianainjelwa?source=rss-dac709fc4208------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_x6fUMtZoFdjfQ2Ie-uuUw.png</url>
            <title>Stories by  Diana Injelwa on Medium</title>
            <link>https://medium.com/@dianainjelwa?source=rss-dac709fc4208------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:36:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dianainjelwa/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[SQL INDEXES]]></title>
            <link>https://medium.com/@dianainjelwa/sql-indexes-42f53c547efc?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/42f53c547efc</guid>
            <category><![CDATA[sql-index]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Fri, 17 May 2024 09:16:24 GMT</pubDate>
            <atom:updated>2024-05-17T09:16:24.003Z</atom:updated>
            <content:encoded><![CDATA[<p>Introduction</p><p>Hello data enthusiast! In today’s article we will have a look at SQL indexes. Indexes are database objects that improve the performance of data retrieval operations by allowing users to quickly find and locate specific data in a table. There are different types of indexes in SQL, with the most common being non-clustered and clustered indexes.</p><h4><strong>Non-Clustered Indexes</strong></h4><p>A good example of a non-clustered index is a textbook index. Non-clustered indexes do not alter the physical order of data in a table, instead they create a separate data structure to store the index data. In relational database management systems, a table can have multiple non-clustered indexes.</p><h4><strong>Syntax:</strong></h4><pre>CREATE INDEX index_name<br>ON table_name(column);</pre><ul><li><strong>index_name</strong>: The name of the index you are creating. It must be unique within the database.</li><li><strong>table_name:</strong> The name of the table on which you are creating the index.</li><li><strong>column</strong>: The column or columns on which you want to create an index.</li></ul><h4><strong>Example:</strong></h4><p>The following code creates an index named ix_salary on the salary column in the employee table.</p><pre>CREATE INDEX ix_salary<br>ON employee(salary);</pre><h4><strong>Clustered indexes</strong></h4><p>Clustered indexes determine the physical order of data in a table. In relational databases, a table can only have one clustered index. A clustered index can include multiple columns, which is referred to as a composite index.</p><p><strong>Note: </strong>A primary key constraint will automatically create a clustered index on that column.</p><h4><strong>Syntax:</strong></h4><pre>CREATE CLUSTERED INDEX ix_customer_id<br>ON customer(customer_id);</pre><h4><strong>Differences between clustered and non-clustered indexes</strong></h4><p><strong>1. Number of indexes:</strong></p><ul><li>A table can only have one clustered index whereas it can have multiple non-clustered indexes.</li></ul><p><strong>2. Performance:</strong></p><ul><li>Clustered indexes are generally faster because they determine the physical order of data and do not require additional lookup steps.</li><li>Non-clustered indexes refer back to the table if the selected column is not present in the index, which can introduce a slight performance overhead.</li></ul><p><strong>3. Storage:</strong></p><ul><li>Clustered indexes do not require extra storage space as they simply determine the order of rows in a table.</li><li>Non-clustered indexes are stored separately from the table, therefore requiring additional storage space.</li></ul><h4><strong>Conclusion</strong></h4><p>Indexes are an essential component of SQL databases since they significantly enhance the speed and efficiency of data retrieval operations.</p><p>Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42f53c547efc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Telecom Customer Churn Analysis]]></title>
            <link>https://medium.com/@dianainjelwa/telecom-customer-churn-analysis-3599680d73e3?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/3599680d73e3</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[customer-churn-analysis]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 15:59:43 GMT</pubDate>
            <atom:updated>2024-04-04T16:01:04.309Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Introduction</strong></h4><p>One challenge that reigns supreme in the dynamic landscape of business is customer churn. Its the one factor that can undermine even the most meticulously crafted strategies. In this article, we will use data from a telecommunications company to uncover insights that empower businesses to not only retain their valuable clientele but also thrive with confidence in the ever-evolving marketplace.</p><h4><strong>Problem Statement</strong></h4><p>Swift Wave Communications is a telecommunications company that offers phone and internet services to 7043 customers in California. They have provided us with a dataset containing churn data for the last quarter (Q2 2022). The dataset includes details about customer demographics, location, services they have subscribed to and current status. Their request entails conducting an analysis to address specific inquiries:</p><ol><li>How many customers joined the company during the last quarter?</li><li>What is the customer profile for a customer that churned, joined, and stayed? Are they different?</li><li>What seem to be the key drivers of customer churn?</li><li>Is the company losing high value customers? If so, how can they retain them?</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I6VBFabeIohrGmBOefI7zw.png" /><figcaption>Sample dataset</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAY8gtv8ymqZvfVmYit4Kw.png" /><figcaption>Data dictionary</figcaption></figure><h4><strong>Data Cleaning</strong></h4><p>The dataset consists of 39 columns and 7,043 rows, with 12 columns containing null values. To address this, we will utilize the guidelines outlined in the data dictionary to impute the missing values.</p><ol><li><strong>Fill in the blank values in each column with the respective values specified in the data dictionary:</strong></li></ol><ul><li>Blank values in the ‘Avg Monthly Long Distance’ and ‘Avg Monthly GB Download’ columns will be replaced with ‘0’ (zero).</li><li>Blank values in the ‘Internet Type’ column will be replaced with ‘None’.</li><li>Blank values in the rest of the columns will be replaced with ‘No’.</li></ul><p>To accomplish this, we will insert a new column and use the IF() and ISBLANK() formula to fill the blanks in the ‘Avg Monthly Long Distance’, and then repeat the same steps for the other columns as demonstrated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*t58SjPhEl8yFFE89NIdj1A.png" /></figure><p>2.<strong> Create new columns named ‘Age Buckets’ and ‘Tenure Buckets’ based on the existing ‘Age’ and ‘Tenure (in months)’ columns.</strong></p><p>For the ‘Age Buckets’ column, customers will be categorized into three age groups:</p><ul><li>Young Adults: Customers aged 39 or younger</li><li>Middle-aged Adults: Customers aged between 40 and 59</li><li>Old Adults: Customers aged 60 or older</li></ul><p>We will utilize a nested IF statement to group the customers, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*Wo4dTJ1sSgMWRCxAqJDJ4Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/201/1*hAKsumYfoaJxtAHAlLtlIg.png" /></figure><p>Similarly, for the ‘Tenure (in months)’ column, we will create a new column named ‘Tenure Buckets’ and categorize customers into four groups based on their tenure. This will enable us to effectively analyze tenure patterns</p><ul><li>1–20 months</li><li>20–40 months</li><li>40–60 months</li><li>More than 60 months</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*5kyoTyUMFGmj5Y2bs5giwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*Alspw_z8jbMcSl4E20sicg.png" /></figure><p>3.<strong> Create a new column ‘Marital Status’ derived from the existing ‘Married’ column, where ‘Yes’ values will be substituted with ‘Married’ and ‘No’ values with ‘Single’.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*CmYo6q9Yc2H594q1a6cOoA.png" /></figure><h4><strong>Key business questions</strong></h4><p>Now that we have an enhanced dataset, we’re ready to delve into our analysis and provide insights into the core business questions we initially identified.</p><ol><li><strong>How many customers joined the company during the last quarter?</strong></li></ol><p>We will use a Pivot Table to determine the count of customers classified under the categories of Joined, Churned, and Stayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*8AXLZWrvvHmyZjvVH41MxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*PAUi4I2jrizNF1TZRKCDQw.png" /></figure><p>2.<strong> What is the customer profile for a customer that churned, joined, and stayed? Are they different</strong>?</p><p>To assess whether there are differences in the customer profiles among churned, joined and stayed customers, we will conduct a comparative analysis of relevant numerical and categorical columns.</p><ul><li>For numerical columns such as Age, Number of dependents, Tenure in months and Total revenue, we will calculate the averages across the different status categories.</li><li>For categorical columns like Gender, Marital Status and Contract Type, we will determine the count of customers within each status segment.</li></ul><p><strong>Pivot Table showing the average age, number of dependents, tenure and revenue across the different status categories.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*X1nea0chU9lG36oYMa0hAg.png" /></figure><ul><li>We observe that the average age of churned customers is 50, with no dependents, an average subscription duration of 18 months and an average revenue contribution of $1,971.</li><li>On the other hand, customers who joined have an average age of 43, no dependents, a subscription duration of 2 months and an average revenue of $120.</li><li>Stayed customers exhibit an average age of 46, with 1 dependent, a subscription duration of 41 months and an average revenue of $3,736.</li></ul><p><strong>Pivot Table showing customer count by gender in each status segment</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*tQjOYGLOtnDIrea8ROp2Rw.png" /></figure><ul><li>In the churned status category, we have 939 female and 930 male customers</li><li>For joined status, there are 243 male and 211 female customers</li><li>And for stayed status, we have 2,382 male and 2,338 female customers.</li></ul><p><strong>Pivot Table showing customer count by marital status in each status segment</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*WJp9dlKKTpqVcU-u3NPqBg.png" /></figure><p>We observe that single customers dominate both the churned and joined status categories.</p><ul><li>Specifically, in the churned category, there are 1,200 single customers compared to 699 married customers.</li><li>In the joined category, there are 370 single customers and 84 married customers.</li><li>As for the stayed category, there are 2,071 single customers and 2,649 married customers.</li></ul><p><strong>Pivot Table showing customer count by contract type in each status segment</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*GwqKAEF7zuC3_gJG1-ZiXA.png" /></figure><p>From the above table, we note that month-to-month contract type is prevalent in both churned and joined categories.</p><ul><li>For churned category, we have 1,655 customers on month-to-month contract type, 166 on a one year contract and 48 on a two year contract.</li><li>For the joined status 408 customers are on month-to-month contract, 24 on one year contract and 22 on a two year contract.</li><li>In the stayed status category, we have 1,547 customers on month-to-month contract, 1,360 customers on a one year contract and 1,813 customers on a two year contract.</li></ul><p>3. <strong>What seems to be the key driver of customer churn?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*ga8VcqOhxuHGL67lILbWpA.png" /></figure><p>From the result above, the primary factors contributing to customer churn are as follows:</p><ul><li>Competition: 45% of churned customers attributed their exit to the company’s competitors.</li><li>Dissatisfaction: Approximately 17.17% of churned customers left due to dissatisfaction with the company’s services.</li><li>Attitude: 16.80% of churned customers mentioned the attitude of support personnel as a contributing factor to their exit.</li></ul><p>4. <strong>Is the company losing high value customers? If so how can they retain them?</strong></p><p>For us to conclude whether the company is losing high value customers, we will assess various factors including; analyzing the average churned revenue with respect to tenure in months and contract type</p><p><strong>Pivot Table showing average churned revenue by tenure in months</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*GvmD24oJwTEMi-i3y-RQ-g.png" /></figure><p>The average revenue from churned customers varies based on their subscription duration:</p><ul><li>Customers with a subscription duration of more than 60 months contribute an average churned revenue of $8,247.</li><li>For customers with a subscription duration of 40 to 60 months, the average churned revenue is $5,481.</li><li>Customers with a subscription duration of 20 to 40 months contribute an average churned revenue of $3,121.</li></ul><p><strong>Pivot Table showing churned revenue by contract type</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*QgWtGXwOR5yP4WuZB0tgdw.png" /></figure><p>The average churned revenue varies based on the type of contract:</p><ul><li>Customers on a two-year contract contribute an average churned revenue of $6,997.</li><li>For customers on a one-year contract, the average churned revenue is $5,171.</li><li>Customers on a month-to-month contract have an average churned revenue of $1,504.</li></ul><p><strong>Analysis Insights</strong></p><ol><li><strong>Joined Customers: </strong>454 customers joined the company during the last quarter (Q2 2022)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*6p_BgukHBbKpl_w25znJYw.png" /></figure><p><strong>2. Customer Profile: </strong>The customer profiles of a customer who churned, joined or stayed are not similar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*W9iRh4Ha5B0RPFC09c6D-w.png" /></figure><p>3. <strong>Key drivers of churn: </strong>Competition, dissatisfaction and attitude are the top three drivers of customer churn, contributing 45%, 17.17% and 16.8% of churned customers respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*_G9UO0ZJicINdCC7hIh7xQ.png" /></figure><h4><strong>Recommendations</strong></h4><p>Here are some recommendations for the company to enhance customer retention:</p><ol><li><strong>Enhance Service Quality:</strong> Listen to customer feedback and incorporate their suggestions to improve the quality of services. By addressing customer preferences, the company can prevent churn caused by competitors offering superior services.</li><li><strong>Implement Comprehensive Training Programs:</strong> Invest in thorough training programs to equip support personnel with the technical skills necessary for effective communication with customers. Ensuring staff are well-prepared to assist customers can strengthen satisfaction and loyalty.</li><li><strong>Actively Address Dissatisfaction:</strong> Take proactive steps to address customer dissatisfaction by actively listening to their feedback. By acknowledging and resolving customer concerns promptly, the company can cultivate stronger relationships and mitigate churn.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8GzFJobt7Wz2Ph4egtPpSw.png" /><figcaption>Dashboard</figcaption></figure><p>Thanks for reading!</p><p><a href="https://1drv.ms/x/s!AtCueeLqdbmnxEmpqOLpsh2HdBNq">Link to the Excel Workbook</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3599680d73e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DELETE, TRUNCATE, DROP SQL COMMANDS]]></title>
            <link>https://medium.com/@dianainjelwa/delete-truncate-drop-sql-commands-0ee92848f49e?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ee92848f49e</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Wed, 14 Feb 2024 10:19:44 GMT</pubDate>
            <atom:updated>2024-02-14T10:19:44.177Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*5tIqlJWXmbkQKnfBxY4mig.png" /><figcaption><a href="https://www.flaticon.com/free-icon/mysql_919836?term=mysql+logo&amp;page=1&amp;position=1&amp;origin=search&amp;related_id=919836">MySQL icon from flaticon.com by Freepik</a></figcaption></figure><h4><strong>Introduction</strong></h4><p><strong>‘DELETE’</strong>, ‘<strong>TRUNCATE’</strong> and ‘<strong>DROP’ </strong>commands play a crucial role in managing and modifying database tables. In this article, we will look at the distinct functionalities of these commands.</p><h4><strong>DELETE</strong></h4><p><strong>‘DELETE’ </strong>is a DML(Data Manipulation Language) command and it is used to delete single or multiple rows from a database table. ‘<strong>WHERE’</strong> clause can be used with this command to filter specific data from database table. ‘<strong>DELETE’ </strong>command is transaction safe that is, we can restore the deleted data using ‘<strong>ROLLBACK’ </strong>statement.</p><pre>-- Syntax with WHERE clause<br>DELETE FROM &quot;table_name&quot;<br>WHERE &quot;condition&quot;;<br><br>-- Syntax without WHERE clause<br>DELETE FROM &quot;table_name&quot;<br></pre><h4><strong>TRUNCATE</strong></h4><p><strong>‘TRUNCATE’</strong> is a DDL(Data Definition Language) command and it is used to delete all rows of a database table. We cannot use this command to delete single rows, hence <strong>‘WHERE’</strong> clause is not used with this command. <strong>‘TRUNCATE ‘</strong> is not transaction safe i.e. we cannot restore deleted data after executing this command.</p><pre>-- Syntax<br>TRUNCATE FROM &quot;table_name&quot;<br>       <br>        -- OR<br><br>TRUNCATE &quot; table_name&quot;</pre><h4><strong>DROP</strong></h4><p><strong>‘DROP’ </strong>is a DDL(Data Definition Language) command and it is used to delete the whole structure of a database table. Similar to <strong>‘TRUNCATE’</strong>, we cannot use<strong> ‘WHERE’</strong> clause with this command and it is also not transaction safe.</p><pre>-- Syntax<br>DROP TABLE &quot;table_name&quot;</pre><h4><strong>Conclusion</strong></h4><p>In conclusion, these three commands serve distinct purposes in database management. The key differences between these three commands can be summarized as follows:</p><ul><li><strong>‘DELETE’</strong> is categorized as a Data Manipulation Language (DML) command, whereas <strong>‘TRUNCATE’</strong> and <strong>‘DROP’</strong> fall under Data Definition Language (DDL) commands.</li><li>The <strong>‘DELETE’ </strong>command allows the use of <strong>‘WHERE’</strong> clause for targeted data deletion, while <strong>‘TRUNCATE’</strong> and <strong>‘DROP’</strong> do not support the use of a <strong>‘WHERE’</strong> clause.</li><li><strong>‘DELETE’</strong> is transaction-safe, offering the ability to restore deleted data using the <strong>‘ROLLBACK’</strong> statement. Conversely, <strong>‘TRUNCATE’</strong> and <strong>‘DROP’</strong> are not transaction-safe, making the deleted data irrecoverable.</li><li>Both <strong>‘DELETE’</strong> and <strong>‘TRUNCATE’</strong> retain the table schema, while <strong>‘DROP’</strong> not only deletes data but also eliminates the entire table structure, including the schema.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ee92848f49e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conditional Statements in Python]]></title>
            <link>https://towardsdev.com/conditional-statements-in-python-8e8467558f68?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e8467558f68</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[conditional-statements]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Thu, 01 Feb 2024 07:21:24 GMT</pubDate>
            <atom:updated>2024-02-01T14:51:05.390Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*fzWXUiBuIfdo7HiyuA4QVg.png" /></figure><h4><strong>Introduction</strong></h4><p>Conditional statements are useful for data analysts as we will often need to filter and extract specific subsets of data based on certain conditions. Conditional statements allow us to define the criteria for selecting relevant data especially when combined with logical operators such as ‘<strong>and’</strong>, <strong>‘or’</strong> and <strong>‘not’</strong>. The most common conditional statements in Python include; <strong>‘if’</strong>, <strong>‘elif’</strong> and <strong>‘else’</strong>.</p><h4><strong>‘if’ statement</strong></h4><p><strong>‘if’</strong> statement executes a block of code if the the specified condition is True.</p><pre># Assign the value 20 to variable &#39;x&#39;.<br>x = 20<br><br># Check if the value of &#39;x&#39; is greater than 10.<br>if x &gt; 10:<br>    # Specify the message to be printed if the condition is True.<br>    print(&#39;x is greater than 10&#39;)</pre><p>The output for the above code will be True because the value of <strong>‘x’</strong> is 20 which is greater than 10.</p><h4><strong>‘if-else’ statement</strong></h4><p>‘if-else’ statement allows us to specify two blocks of code, one to be executed if the condition is True and another to be executed if the condition is False.</p><pre># Assign the string  value &#39;Chocolate&#39; to the variable &#39;ice_cream&#39;.<br>ice_cream = &#39;Chocolate&#39;<br><br># Check if the lexicographic order of the string &#39;ice_cream&#39; is greater than the string &#39;Vanilla&#39;.<br>if ice_cream &gt; &#39;Vanilla&#39;:<br>    # Specify the message to be printed if the condition is True.<br>    print(&#39;C is greater than V&#39;)<br>else:<br>    # Specify the  message to be printed if the condition is False.<br>    print(&#39;C is not greater than V&#39;)</pre><p>The output for the above code will be <strong>‘C is not greater than V’</strong>. This<strong> </strong>is because in alphabetical order &#39;C&#39; comes before &#39;V&#39;, so the first condition evaluates to False, and the code block under the <strong>‘else’</strong> statement is executed.</p><h4><strong>‘if-elif-else’ statement</strong></h4><p>‘if-elif-else’ statement allows us to check multiple conditions and execute different blocks of code based on the first True condition encounter.</p><pre># Assign  the value 17 to the variable &#39;x&#39; .<br>x = 17<br><br># Check if the value of &#39;x&#39; is greater than 20.<br>if x &gt; 20:<br>    # Specify the messange to be printed if the condition is True.<br>    print(&#39;x is greater than 20&#39;)<br># If the first condition is False, check if the value of &#39;x&#39; is greater than 15.<br>elif x &gt; 15:<br>    # Specify the messange to be printed if the  second condition is True.<br>    print(&#39;x is greater than 15 but less than 20&#39;)<br>else:<br>    # Specify the message to be printed if both conditions are False<br>    print(&#39;x is 15 or less&#39;)</pre><p>The output for the above code will be <strong>‘x is greater than 15 but less than 20’ </strong>because the first condition evaluates to False and the code under the <strong>‘elif’</strong> statement is executed which evaluates to True.</p><h4><strong>Practice Question</strong></h4><p><a href="https://www.hackerrank.com/challenges/py-if-else/problem?isFullScreen=true">Here is one of the many questions on HackerRank that you can use to practice</a></p><p><strong>Task</strong><br>Given an integer <strong>’n’</strong>, perform the following conditional actions:</p><ul><li>If<strong> ’n’</strong> is odd, print Weird</li><li>If <strong>’n’</strong> is even and in the inclusive range of 2 to 5 , print Not Weird</li><li>If <strong>’n’ </strong>is even and in the inclusive range of 6 to 20 , print Weird</li><li>If <strong>’n’</strong> is even and greater than 20, print Not Weird</li></ul><pre># Take user input, convert it to an integer and assign it to the variable &#39;n&#39;.<br>n = int(input(&quot;Enter an integer between 1 and 100: &quot;))<br><br>&quot;&quot;&quot; We check if an integer is odd or even using the modulo operator &#39;%&#39;.<br>If the result of &#39;n % 2&#39; is equal to one then the number is odd else the number is even<br>&quot;&quot;&quot;<br><br># Check if &#39;n&#39; is within the allowed range [1, 100].<br>if 1 &lt;= n &lt;= 100:<br>    # Check if &#39;n&#39; is odd.<br>    if n % 2 != 0:<br>        # Specify the message to be printed if &#39;n&#39; is odd.<br>        print(&quot;Weird&quot;)<br>    # Check if &#39;n&#39; is even and falls within the range [2, 5].<br>    elif n % 2 == 0 and 2 &lt;= n &lt;= 5:<br>        # Specify the message to be printed if the above condition is True.<br>        print(&quot;Not Weird&quot;)<br>    # Check if &#39;n&#39; is even and falls within the range [6, 20].<br>    elif n % 2 == 0 and 6 &lt;= n &lt;= 20:<br>        # Specify the message to be printed if the above code evaluates to True.<br>        print(&quot;Weird&quot;)<br>    # Check if &#39;n&#39; is even and greater than 20.<br>    elif n % 2 == 0 and n &gt; 20:<br>        # Specify the message to be printed if the above condition is True.<br>        print(&quot;Not Weird&quot;)<br>else:<br>    # Specify the message to be printed is &#39;n&#39; is outside the range [1, 100]<br>    print(&quot;Input is outside the allowed range [1, 100].&quot;)</pre><p>In conclusion, conditional statements in Python are powerful as they allow us to control the flow of programs based on specified conditions.</p><p><a href="https://github.com/Diana-Injelwa/Python-Fundamentals">Python code on my GitHub.</a></p><p>Remember that you are intelligent and you can learn. Happy learning data nerds!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e8467558f68" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/conditional-statements-in-python-8e8467558f68">Conditional Statements in Python</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Variables in Python]]></title>
            <link>https://medium.com/@dianainjelwa/variables-in-python-2dc361e98317?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dc361e98317</guid>
            <category><![CDATA[variables]]></category>
            <category><![CDATA[variables-in-python]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Mon, 22 Jan 2024 07:32:16 GMT</pubDate>
            <atom:updated>2024-01-22T14:40:17.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*1IiJBjloxFdI6-ild8Pe5Q.png" /></figure><h4><strong>Introduction</strong></h4><p>Python has become a predominant language in the field of data analytics due to its user-friendly syntax, extensive support for data-related libraries such as Pandas for data manipulation, NumPy for numerical computing and Matplotlib and Seaborn for data visualization. In this article, we will begin by looking at variables as they are the building block of any programming language. Moreover, understanding variables in Python is essential for data manipulation and all subsequent data analysis tasks.</p><h4><strong>Definition</strong></h4><p>A variable is a named location in a computer’s memory where we can store data and later retrieve the data using the variable name. We assign a value to a variable using the assignment operator (=).</p><pre># Assigning the value 22 to the variable x<br>x = 22<br><br># Printing the value of x<br>print(x)<br><br># Assigning the string value &#39;Mint chocolate chip&#39; to the variable ice_cream_flavour<br>ice_cream_flavour = &#39;Mint chocolate chip&#39;<br><br># Printing the value of ice_cream_flavour<br>print(ice_cream_flavour)</pre><h4><strong>Checking the ‘Type’ of a variable</strong></h4><p>When assigning a value to a variable, we don’t have to explicitly declare the data type of a variable since Python determines the data type based on the assigned values. However, we use the function ‘type()’ to check the data type of a variable.</p><pre># Checking the data type of variable &#39;x&#39;<br>type(x)<br><br># Checking the data type of variable &#39;ice_cream_flavour&#39;<br>type(ice_cream_flavour)</pre><h4><strong>Assigning values to multiple variables</strong></h4><p>So far we have only assigned one value to one variable. We can also assign values to multiple variables in a single line of code as shown below.</p><pre># Assigning values to multiple variables in a single line<br>brand,cream_flavour,price = &#39;Dairyland&#39;, &#39;Salted Caramel&#39;, 660<br><br># Printing the value of the variable &#39;brand&#39;<br>print(brand)<br><br># Printing the value of the variable &#39;cream_flavour&#39;<br>print(cream_flavour)<br><br># Printing the value of the variable &#39;price&#39;<br>print(price)</pre><h4><strong>Assigning lists to variables</strong></h4><p>We can also create a list and assign it to a variable. In Python we create a list using square brackets ‘[]’ and separating the elements with commas(,).</p><pre># Creating a list of favorite ice cream flavours<br>favourite_flavours = [&#39;Salted caramel&#39;, &#39;Classic vanilla&#39;, &#39;Lemon and Lime&#39;]<br><br># Assigning elements from the list of favorite ice cream flavors to individual variables representing different ice cream brands<br>dairyland, creambell, lyons_maid = favourite_flavours<br><br># Printing the assigned values<br>print(dairyland, &#39;is my favourite ice cream flavour from dairyland&#39;)<br>print(creambell, &#39;is my favourite ice cream flavour from creambell&#39;)<br>print(lyons_maid, &#39;is my favourite ice cream flavour from lyons maid&#39;)</pre><h4><strong>Reassigning variables</strong></h4><p>We can overwrite a previous variable by assigning a new value to it. We had assigned the value ‘Mint chocolate chip’ to the variable ‘ice_cream_flavour’. We will assign a new value ‘Choc chip’ to this variable.</p><pre># Printing the value of &#39;ice_cream_flavour&#39; before its reassignment<br>print(ice_cream_flavour)<br><br># Assigning the string &#39;Choc chip&#39; to the variable &#39;ice_cream_flavour&#39;<br>ice_cream_flavour = &#39;Choc chip&#39;<br><br># Printing the updated value of &#39;ice_cream_flavour&#39;<br>print(ice_cream_flavour)</pre><h4><strong>Variable naming rules</strong></h4><ul><li>Variable names can only start with a letter that is (a-z or A-Z) or an underscore (_)</li><li>Variable names can contain letters, numbers and underscores</li><li>Variable names cannot start with a number</li><li>Variable names cannot be any of the Python keywords</li><li>Python is case sensitive, therefore variables such as ‘TestVar’, ‘testvar’ and ‘testVar’ are all different</li><li>Use mnemonic names that is variable names that will be easier for someone to understand and help us remember what we intend to store in them</li></ul><h4><strong>Techniques to use when writing variable names with more than one word</strong></h4><ol><li>Camel case: Each word except the first starts with a capital letter</li></ol><pre># Using Camel Case to name variables<br>secondFavouriteFlavour = &#39;Vanilla swirl&#39;<br><br>print(secondFavouriteFlavour)</pre><p>2. Pascal case: For this technique, each word starts with a capital letter</p><pre># Using Pascal case to name variables<br>LeastFavouriteFlavour = &#39;Strawberry&#39;<br><br>print(LeastFavouriteFlavour)</pre><p>3. Snake case: Each word is separated by an underscore (_). Its the most recommended technique because it improves code readability.</p><pre># Using Snake case to name variables<br>favourite_flavour = &#39;Salted caramel&#39;<br><br>print(favourite_flavour)</pre><h4><strong>Conclusion</strong></h4><p>In conclusion, understanding variables is fundamental in Python programming, especially in the context of data analytics.</p><p>Happy learning data nerds!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dc361e98317" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WINDOW CLAUSE]]></title>
            <link>https://medium.com/@dianainjelwa/window-clause-ae2e8a817477?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae2e8a817477</guid>
            <category><![CDATA[window-functions]]></category>
            <category><![CDATA[sql-tips]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Thu, 11 Jan 2024 10:44:19 GMT</pubDate>
            <atom:updated>2024-01-11T10:44:19.543Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Introduction</strong></h4><p>When using window functions in SQL, you can define and assign names to windows using a WINDOW clause, allowing you to refer to them in OVER clauses. The WINDOW clause is positioned between the HAVING and ORDER BY clauses.</p><p>Syntax:</p><pre>WINDOW window_name AS (window_spec)</pre><ul><li>window_name is the window name</li><li>window_spec is the same type of window specification as given in the OVER clause</li></ul><h4><strong>Sample Question</strong></h4><p>To demonstrate the functionality of the WINDOW clause, we will consider the following example question:</p><p><strong>Find the second most expensive product and the least expensive product within each category from the product table.</strong></p><p>Ideally, the query to answer this question is as shown below.</p><pre>SELECT *,<br>    NTH_VALUE(product_name, 2)<br>        OVER(PARTITION BY product_category ORDER BY price DESC<br>            RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS 2nd_most_exp_product,<br>    LAST_VALUE(product_name)<br>          OVER(PARTITION BY product_category ORDER BY price DESC<br>              RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS least_expensive_product<br>FROM product;</pre><h4><strong>Using WINDOW clause</strong></h4><pre>SELECT *,<br>    NTH_VALUE(product_name, 2) OVER w AS 2nd_most_exp_product,<br>    LAST_VALUE(product_name) OVER w AS least_expensive_product<br>FROM product<br>WINDOW w AS(PARTITION BY product_category ORDER BY price DESC<br>            RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)</pre><h4><strong>Advantages of using WINDOW clause</strong></h4><ul><li><strong>Enhanced Readability:</strong> The WINDOW clause is beneficial for queries where multiple OVER clauses would define the same window. This improves code readability by consolidating window definitions.</li><li><strong>Ease of Experimentation</strong>: The WINDOW clause simplifies experimentation with window definitions to observe their impact on query results. Instead of modifying multiple OVER clause definitions, you can make changes in a single location within the WINDOW clause.</li></ul><h4><strong>Conclusion</strong></h4><p>In conclusion, WINDOW clause offers significant advantages in SQL queries. It not only contributes to cleaner code but also facilitates efficient exploration of queries by providing a manageable way to adjust widow specifications.</p><p><a href="https://medium.com/towardsdev/sql-window-functions-5e24dcde8a66">Feel free to read my previous article on window functions here</a></p><p>Happy learning data nerds!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae2e8a817477" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL WINDOW FUNCTIONS]]></title>
            <link>https://towardsdev.com/sql-window-functions-5e24dcde8a66?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e24dcde8a66</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[sql-window-functions]]></category>
            <category><![CDATA[window-functions]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Tue, 19 Dec 2023 08:47:31 GMT</pubDate>
            <atom:updated>2024-03-21T05:33:31.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*zc8xvspdIiLMMeucyexq7g.png" /></figure><h4><strong>Introduction</strong></h4><p>Window functions are functions in relational databases that perform aggregate-like operations on a set of query rows and produces results for each query row. A window operation is signified by including an OVER() clause. This clause can remain empty, implying that the window function will compute results using all rows. Alternatively, we can use a PARTITION BY clause which specifies how to partition the query rows into groups and an ORDER BY clause which indicates how to sort rows in each partition. We will use data from <strong>employee </strong>table and <strong>product</strong> table as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*KwIMjcuAJC-roSHQiKlTng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*YnMfpmzNSyMsN8U39sWu_A.png" /></figure><h4><strong>Commonly used window functions include:</strong></h4><ol><li><strong>ROW_NUMBER()</strong> : Assigns a unique number to each row within its partition.</li></ol><p><strong>Retrieve the first two employees who joined the company from every department.</strong></p><pre>/* To answer this question we assume that emp_id of<br>employees who joined earlier is smaller than that of <br>employees who joined later on */ <br>SELECT emp_id, emp_name, department<br>FROM(<br>    SELECT *,<br>        ROW_NUMBER() OVER(PARTITION BY department ORDER BY emp_id) AS rn<br>    FROM employee<br>) subquery<br>WHERE subquery.rn &lt; 3;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*qrFWVHLh-OcqNj1n_KbMGQ.png" /></figure><p>2. <strong>RANK() </strong>: Assigns a rank to each row within its partition, with duplicated records receiving the same rank and leaving gaps in the ranking sequence (skips a value when assigning the next rank)</p><p><strong>Retrieve the three highest-earning employees in each department.</strong></p><pre>SELECT emp_name, department, salary<br>FROM(<br>    SELECT *,<br>        RANK() OVER(PARTITION BY department ORDER BY salary DESC) AS rnk<br>    FROM employee<br>) subquery<br>WHERE subquery.rnk &lt; 4;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*At3R3chmH0ZDARGe0FTZ1A.png" /></figure><p>3. <strong>DENSE_RANK()</strong> : Its similar to Rank() but the difference is that DENSE_RANK() leaves no gaps in the ranking sequence when there are duplicated records.</p><pre>SELECT *,<br>    RANK() OVER(PARTITION BY department ORDER BY salary DESC) AS rnk,<br>    DENSE_RANK() OVER(PARTITION BY department ORDER BY salary DESC) AS d_rnk<br>FROM employee;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*NnvepVfLH1Z3V0RxQJI0Zw.png" /><figcaption>Comparison between RANK() and DENSE_RANK()</figcaption></figure><p>4. <strong>LEAD() </strong>: Often used to get succeeding value of any row within its partition. This window function takes three arguments i.e. LEAD(expr, N, default)</p><ul><li><strong>expr : </strong>Can be a column or any inbuilt function</li><li><strong>N : </strong>A<strong> </strong>positive value which determine number of rows succeeding the current row. If omitted default value is 1.</li><li><strong>default : </strong>The value to be returned by function in-case no row succeeds the current row by <strong>N</strong> rows; the default value is NULL</li></ul><p><strong>Write a query to check whether an employee’s salary surpasses, matches or falls below the salary of the subsequent employee.</strong></p><pre>SELECT emp_id, emp_name, department, salary,<br>    CASE<br>        WHEN salary &gt; next_emp_salary THEN &quot;Higher than next employee&#39;s salary&quot;<br>        WHEN salary &lt; next_emp_salary THEN &quot;Lower than next employee&#39;s salary&quot;<br>        WHEN salary = next_emp_salary THEN &quot;Same as next employee&#39;s salary&quot;<br>    END AS next_salary_comparison<br>FROM(<br>    SELECT *,<br>        LEAD(salary) OVER(PARTITION BY department ORDER BY emp_id) AS next_emp_salary<br>    FROM employee<br>) subquery;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*UYDAcAeU1IVXr9L8dCGzig.png" /></figure><p>5. <strong>LAG()</strong> : Often used to get preceding value of any row within its partition. This window function takes three arguments i.e. LAG(expr, N, default)</p><ul><li><strong>expr : </strong>Can be a column or any built-in function</li><li><strong>N : </strong>A<strong> </strong>positive value which determine number of rows preceding the current row. If omitted default value is 1.</li><li><strong>default : T</strong>he value to be returned by function in-case no row precedes the current row by <strong>N</strong> rows; the default value is NULL</li></ul><p><strong>Determine whether an employee’s salary exceeds, equals or is less than the salary of the preceding employee.</strong></p><pre>SELECT emp_id, emp_name, department, salary,<br>    CASE<br>        WHEN salary &gt; previous_salary THEN &quot;Higher than previous employee&#39;s salary&quot;<br>        WHEN salary &lt; previous_salary THEN &quot;Lower than previous employee&#39;s salary&quot;<br>        WHEN salary = previous_salary THEN &quot;Same as previous employee&#39;s salary&quot;<br>    END AS salary_comparison<br>FROM(<br>    SELECT *,<br>        LAG(Salary) OVER(PARTITION BY department ORDER BY emp_id) AS previous_salary<br>    FROM employee    <br>) subquery;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*KS01bsOFjoP0pPUoZU2NMw.png" /></figure><p>6. <strong>FIRST_VALUE() </strong>: Returns the value of a specified expression from the first row of the window frame. This function accepts one argument i.e. The column for which you want to find the first value.</p><p><strong>Find the most expensive product under each category.</strong></p><pre>SELECT *,<br>    FIRST_VALUE(product_name) OVER(PARTITION BY product_category ORDER BY price DESC) AS most_expensive_product<br>FROM product;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*DQ94glSIN5Hzc59NesgqTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*iaue4LeKOPfQDtTtmKIPIA.png" /></figure><p>7.<strong> </strong><strong>LAST_VALUE()</strong> : Returns the value of a specified expression from the last row of the window frame. This function accepts one argument i.e. The column for which you want to find the last value.</p><p><strong>What is the least expensive product under each category?</strong></p><pre>/* NOTE: It is important to specify the right Frame Clause when using LAST_VALUE() AND NTH_VALUE()<br>    window function so as the function can have access to all the records of <br>    the partitions. The default Frame Clause in MySQL is <br>    &quot;RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW&quot; which we need to modify<br>    to &quot;RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING&quot; in order to get<br>    the correct results set */<br>SELECT *,<br>    LAST_VALUE(product_name)<br>        OVER(PARTITION BY product_category ORDER BY price DESC<br>            RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS least_expensive_product<br>FROM product;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*Mjt1j_dkXBdF4uljZzKu6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*Eo3iJbikk25y0KE-QdpegQ.png" /></figure><p>8. <strong>NTH_VALUE() </strong>: Returns the value of a specified expression from the <strong>N-th</strong> row of the window frame and returns <strong>NULL </strong>if there is no such row. This function takes two arguments NTH_VALUE(expr, N)</p><ul><li><strong>expr</strong> : The column for which you want to find the nth value</li><li><strong>N </strong>: The position of the value you want to retrieve within the window frame (N must be a positive integer)</li></ul><p><strong>What is the second most expensive product under each category?</strong></p><pre>SELECT *,<br>    NTH_VALUE(product_name, 2)<br>        OVER(PARTITION BY product_category ORDER BY price DESC<br>            RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS 2nd_most_exp_product<br>FROM product;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*H-MMTdCT0s1m7aCQdJ8e4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*5OpA5GKRR7jmGabF69oxLA.png" /></figure><p>9.<strong> </strong><strong>NTILE() </strong>: Divides a partition into <strong>N </strong>groups (buckets), assigns each row in the partition its bucket number, and returns the bucket number of the current row within its partition. This function accepts one argument NTILE(N) where <strong>N </strong>is the<strong> </strong>number of groups (buckets) into which you want to divide the result set and must be a positive integer.</p><p><strong>Group all the Phones into expensive phones, mid range phones and cheaper phones.</strong></p><pre>SELECT product_name, price,<br>    CASE<br>        WHEN buckets = 1 THEN &#39;Expensive&#39;<br>        WHEN buckets = 2 THEN &#39;Mid-range&#39;<br>        ELSE &#39;Cheaper&#39;<br>    END AS price_bucket<br>FROM(<br>    SELECT *,<br>        NTILE(3) OVER(ORDER BY price DESC) AS buckets<br>    FROM product<br>    WHERE product_category = &#39;Phone&#39;    <br>) subquery;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*h1qrozMl2SrW3HZWDcthgA.png" /></figure><h4><strong>Conclusion</strong></h4><p>Window functions offer powerful tools for performing advanced analytics and gaining deeper insights into data sets. These functions are essential for both data analysts and database professionals, enabling the derivation of valuable insights, informed decision-making and the extraction of maximum value from data sets when integrated into queries.</p><p><a href="https://github.com/Diana-Injelwa/SQL-Window-Functions">Get the SQL script here.</a></p><p>Remember to always back it up with Data! Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e24dcde8a66" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/sql-window-functions-5e24dcde8a66">SQL WINDOW FUNCTIONS</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analyzing the Impact of Sustainable Practices on Sales Performance]]></title>
            <link>https://towardsdev.com/analyzing-the-impact-of-sustainable-practices-on-data-marts-sales-performance-5cb8c171d8c4?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/5cb8c171d8c4</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[8-week-sql-challenge]]></category>
            <category><![CDATA[data-mart]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Mon, 06 Nov 2023 07:01:56 GMT</pubDate>
            <atom:updated>2024-04-05T10:47:47.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Y074UbODJAq9MKLdop7m2Q.png" /></figure><h4><strong>Introduction</strong></h4><p>Data Mart, an online supermarket specializing in fresh produce, underwent significant transformations in June 2020. They implemented sustainable packaging methods across their entire product range i.e. from the farm all the way to the customer. <a href="https://8weeksqlchallenge.com/case-study-5/">In this case study</a>, we will explore an analysis of Data Mart’s sales performance, both pre- and post-implementation of these changes. The aim of this analysis is to quantify the impact brought about by this strategic shift.</p><p>Some of the key business questions that we will address in order to provide valuable insights to the Data Mart team include:</p><ul><li>What was the quantifiable impact of the changes introduced in June 2020?</li><li>Which platform, region, segment and customer types were the most impacted by this change?</li><li>What can we do about future introduction of similar sustainability updates to the business to minimize impact on sales?</li></ul><h4><strong>Available Data</strong></h4><p>The data used in this case study is stored in a single table weekly_sales with the following columns;</p><ul><li>week_date : which indicates the start of the sales week</li><li>region : Data Mart has international operations across the following regions; Asia, USA, Europe, Africa, Canada, Oceania, South America.</li><li>platform : Data Mart has a retail and online shop in the form of Shopify</li><li>segment and customer_type relates to customer’s age and demographics information</li><li>transactions is the count of unique purchases made through Data Mart and sales is the actual amount of purchases.</li></ul><h4><strong>Data Cleaning</strong></h4><p>After creating and populating the table, I conducted essential data cleaning procedures to prepare the dataset for the upcoming phase of data exploration. The following operations were performed, resulting in the generation of a new table named clean_weekly_sales</p><ul><li>Converted the week_date to a DATE format.</li><li>Added a week_number as the second column for each week_date value, for instance values from the 1st of January to 7th of January will be 1, 8th to 14th will be 2 etc.</li><li>Added a month_number with the calendar month for each week_date value as the 3rd column.</li><li>Appended a calendar_year column as the 4th column containing either 2018, 2019 or 2020 values.</li><li>Introduced a new column called age_band after the original segment column. The assignment was based on a mapping of the numbers within the segment value: 1 = Young Adult, 2 = Middle Aged, 3 or 4 = Retirees</li><li>Added a new demographic column, utilizing a mapping system that considers the first letter in the segment values: C = Couples, F = Families</li><li>Ensured all null string values in the original segment column, as well as the new age_band and demographic columns, were replaced with &quot;Unknown&quot; string values..</li><li>Generated a new avg_transaction column, derived from the sales value divided by transactions rounded to two decimal places for each record</li></ul><pre>CREATE TABLE clean_weekly_sales AS<br>SELECT<br>    week_date,<br>    WEEKOFYEAR(week_date) AS week_number,<br>    MONTH(week_date) AS month_number,<br>    YEAR(week_date) AS calender_year,<br>    region,<br>    platform,<br>    CASE<br>        WHEN segment = &#39;null&#39; THEN &#39;Unknown&#39;<br>        ELSE segment<br>    END AS segment,<br>    CASE<br>        WHEN segment LIKE &#39;%1%&#39; THEN &#39;Young Adults&#39;<br>        WHEN segment LIKE &#39;%2%&#39; THEN &#39;Middle Aged&#39;<br>        WHEN segment LIKE &#39;%3%&#39; OR segment LIKE &#39;%4%&#39; THEN &#39;Retirees&#39;<br>        ELSE &#39;Unknown&#39;<br>    END AS age_band,<br>    CASE<br>        WHEN segment LIKE &#39;C%&#39; THEN &#39;Couples&#39;<br>        WHEN segment LIKE &#39;F%&#39; THEN &#39;Families&#39;<br>        ELSE &#39;Unknown&#39;<br>    END AS demographic,<br>    customer_type,<br>    transactions,<br>    sales,<br>    ROUND(sales/transactions, 2) AS avg_transaction<br>FROM weekly_sales;</pre><h4><strong>Data Exploration</strong></h4><ol><li>What day of the week is used for each week_date value?</li></ol><pre>SELECT DISTINCT DAYNAME(week_date) AS day_of_week<br>FROM clean_weekly_sales;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/153/1*zCCU8Dhm9L-XzcC_0sIp9g.png" /></figure><p>2. What range of week numbers are missing from the dataset?</p><pre>WITH RECURSIVE missing_weeks AS(<br>    SELECT 1 AS n<br>    UNION<br>    SELECT n + 1<br>    FROM missing_weeks<br>    WHERE n &lt; 52<br>)<br>SELECT n AS missing_week_numbers<br>FROM missing_weeks<br>WHERE n NOT IN (SELECT DISTINCT week_number FROM clean_weekly_sales);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/190/1*fPhrJFttB7McLDnJ0tY7OQ.png" /></figure><p>3. How many transactions were there for each year in the dataset?</p><p>Data Mart made approximately 346million, 365 million and 375 million transactions in 2018, 2019 and 2020 respectively</p><pre>SELECT<br>    calender_year,<br>    SUM(transactions) AS total_transactions<br>FROM clean_weekly_sales<br>GROUP BY calender_year<br>ORDER BY calender_year;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/1*h4Ec6g18FB5EfcNQKJB7UQ.png" /></figure><p>4. What is the total sales for each region for each month?</p><pre>SELECT<br>    region,<br>    MONTHNAME(week_date) AS month,<br>    SUM(sales) AS total_sales<br>FROM clean_weekly_sales<br>GROUP BY region, month<br>ORDER BY region, month_number;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*3iEP01KUEQRRpmvUcKv7wQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*0MaX3YUN3lESlyBSWGbCKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*Q7lY4717TAGQE3S_xeNrNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*kYYnx3Mc5pIxMcozb-RdHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*ExaZ27Er_AuMKyrWN55hXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*NLzxfgDoAfJX7nKwELmrAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*28sVKNUq56RyksN1RJW4jg.png" /></figure><p>5. What is the total count of transactions for each platform?</p><p>8568 transactions were made via Retail while 8549 transactions were made on Shopify.</p><pre>SELECT<br>    platform,<br>    COUNT(transactions) AS total_transactions<br>FROM clean_weekly_sales<br>GROUP BY platform;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*w54oe40UQxAYUuu8hAj7YQ.png" /></figure><p>6. What is the percentage of sales for Retail vs Shopify each month?</p><p>March had the highest Retail sales percentage 97.54% while August had the highest Shopify sales percentage 2.92%</p><pre>WITH retail_shopify_sales AS(<br>    SELECT<br>        MONTHNAME(week_date) AS month,<br>        SUM(CASE WHEN platform = &#39;Retail&#39; THEN sales END) AS retail_sales,<br>        SUM(CASE WHEN platform = &#39;Shopify&#39; THEN sales END) AS shopify_sales,<br>        SUM(sales) AS total_sales<br>    FROM clean_weekly_sales<br>    GROUP BY month<br>)<br>SELECT<br>    month,<br>    CONCAT(ROUND((retail_sales / total_sales) * 100, 2),&#39;%&#39;) AS retail_percent,<br>    CONCAT(ROUND((shopify_sales / total_sales) * 100, 2),&#39;%&#39;) AS shopify_percent<br>FROM retail_shopify_sales<br>GROUP BY month<br>ORDER BY month;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*ptKEuqY3BRQ-mhfCT06Jpw.png" /></figure><p>7. What is the percentage of sales by demographic for each year in the dataset?</p><p>Customers whose demographic is unknown contributed 41.63%, 40.23% and 38.55% to sales in 2018, 2019 and 2020 respectively.</p><pre>WITH demographics AS(<br>    SELECT<br>        calender_year,<br>        SUM(CASE WHEN demographic = &#39;Couples&#39; THEN sales END) AS couples_sales,<br>        SUM(CASE WHEN demographic = &#39;Families&#39; THEN sales END) AS families_sales,<br>        SUM(CASE WHEN demographic = &#39;Unknown&#39; THEN sales END) AS unknown_sales,<br>        SUM(sales) AS total_sales<br>    FROM clean_weekly_sales<br>    GROUP BY calender_year<br>)<br>SELECT<br>    calender_year,<br>    CONCAT(ROUND((couples_sales / total_sales) * 100, 2),&#39;%&#39;) AS couples_percent,<br>    CONCAT(ROUND((families_sales / total_sales) * 100, 2),&#39;%&#39;) AS families_percent,<br>    CONCAT(ROUND((unknown_sales / total_sales) * 100, 2),&#39;%&#39;) AS unknown_percent<br>FROM demographics<br>GROUP BY calender_year<br>ORDER BY calender_year;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*Ol-eCI6cZl8zQsM3KI0JfA.png" /></figure><p>8. Which age_band and demographic values contribute the most to Retail sales?</p><p>Customers whose age_band and demographic is unknown contributed over 16 billion to Retail sales</p><pre>SELECT<br>    age_band,<br>    demographic,<br>    SUM(sales) AS total_retail_sales<br>FROM clean_weekly_sales<br>WHERE platform = &#39;Retail&#39;<br>GROUP BY age_band, demographic<br>ORDER BY total_retail_sales DESC;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*-ji5HyYAJH5_uHscRDdU0w.png" /></figure><p>9. Can we use the avg_transaction column to find the average transaction size for each year for Retail vs Shopify? If not — how would you calculate it instead?</p><pre>WITH transactions AS(<br>    SELECT<br>        calender_year,<br>        SUM(CASE WHEN platform = &#39;Retail&#39; THEN transactions END) AS retail_trans,<br>        SUM(CASE WHEN platform = &#39;Shopify&#39; THEN transactions END) AS shopify_trans<br>        FROM clean_weekly_sales<br>        GROUP BY calender_year<br>),<br>sales AS(<br>    SELECT<br>        calender_year,<br>        SUM(CASE WHEN platform = &#39;Retail&#39; THEN sales END) AS retail_sales,<br>        SUM(CASE WHEN platform = &#39;Shopify&#39; THEN sales END) AS shopify_sales<br>        FROM clean_weekly_sales<br>        GROUP BY calender_year<br>)<br>SELECT<br>    s.calender_year,<br>    ROUND(AVG((retail_sales / retail_trans)), 2) AS retail_trans_size,<br>    ROUND(AVG((shopify_sales / shopify_trans)), 2) AS shopify_trans_size<br>FROM sales s<br>JOIN transactions t ON s. calender_year = t. calender_year<br>GROUP BY s.calender_year;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*K919fcpJWs5vJ-K1kNZy3Q.png" /></figure><h4><strong>Before and After Analysis</strong></h4><p>This before and after analysis was crucial as it will help us inspect the impact before and after a certain point in time. We set the week_date value of 2020-06-15 as the baseline week i.e. when Data Mart’s sustainable packaging changes came into effect. We would include all week_date values for 2020-06-15 as the start of the period after the change and the previous week_date values would be before. The key business questions addressed through this analysis include:</p><ol><li>What is the total sales for the 4 weeks before and after 2020-06-15? What is the growth or reduction rate in actual values and percentage of sales?</li></ol><p>Data Mart experienced a 1.15% drop in sales for the first 4 weeks after the packaging changes took effect</p><pre>WITH 4_weeks_before AS(<br>    SELECT DISTINCT week_date<br>    FROM clean_weekly_sales<br>    WHERE week_date BETWEEN (DATE_ADD(&#39;2020-06-15&#39;, INTERVAL -4 WEEK)) AND (DATE_ADD(&#39;2020-06-15&#39;, INTERVAL -1 WEEK))    <br>),<br>4_weeks_after AS(<br>    SELECT DISTINCT week_date<br>    FROM clean_weekly_sales<br>    WHERE week_date BETWEEN &#39;2020-06-15&#39; AND (DATE_ADD(&#39;2020-06-15&#39;, INTERVAL 3 WEEK))    <br>),<br>sales AS(<br>    SELECT<br>        SUM(CASE WHEN week_date IN (SELECT * FROM 4_weeks_before) THEN sales END) AS 4weeks_before_sales,<br>        SUM(CASE WHEN week_date IN (SELECT * FROM 4_weeks_after) THEN sales END) AS 4weeks_after_sales<br>    FROM clean_weekly_sales<br>)<br>SELECT *,<br>    (4weeks_after_sales - 4weeks_before_sales) AS variance,<br>    CONCAT(ROUND(((4weeks_after_sales - 4weeks_before_sales) / 4weeks_before_sales) * 100, 2),&#39;%&#39;) AS percentage<br>FROM sales;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*qCJDCzN8ZpKQdtYvdCFJWQ.png" /></figure><p>2. What about the entire 12 weeks before and after?</p><p>For the entire 12 weeks period, there was still an observable pattern revealing a 2.14% decline in sales.</p><pre>WITH 12_weeks_before AS(<br>    SELECT DISTINCT week_date<br>    FROM clean_weekly_sales<br>    WHERE week_date BETWEEN (DATE_ADD(&#39;2020-06-15&#39;, INTERVAL -12 WEEK)) AND (DATE_ADD(&#39;2020-06-15&#39;, INTERVAL -1 WEEK))    <br>),<br>12_weeks_after AS(<br>    SELECT DISTINCT week_date<br>    FROM clean_weekly_sales<br>    WHERE week_date BETWEEN &#39;2020-06-15&#39; AND (DATE_ADD(&#39;2020-06-15&#39;, INTERVAL 11 WEEK))    <br>),<br>sales AS(<br>    SELECT<br>            SUM(CASE WHEN week_date IN (SELECT * FROM 12_weeks_before) THEN sales END) AS 12weeks_before_sales,<br>            SUM(CASE WHEN week_date IN (SELECT * FROM 12_weeks_after) THEN sales END) AS 12weeks_after_sales<br>    FROM clean_weekly_sales    <br>)<br>SELECT *,<br>    (12weeks_after_sales - 12weeks_before_sales) AS variance,<br>    CONCAT(ROUND(((12weeks_after_sales - 12weeks_before_sales) / 12weeks_before_sales) * 100, 2),&#39;%&#39;) AS percentage<br>FROM sales;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*v1PygzTmr_6ykK96YLBi6w.png" /></figure><h4><strong>Recommendations</strong></h4><p>Given the observed 1.15% and 2.24% decline in sales over the 4 weeks and 12 weeks period after implementation of sustainable packaging, It is crucial to address this trend and here are some recommendations Data Mart can put in place:</p><ol><li>Gathering Customer Feedback</li></ol><ul><li>Data Mart’s customer support team should actively gather feedback from customers, specifically focusing on their perceptions of sustainable packaging. This feedback will be instrumental in understanding customer concerns and sentiments.</li><li><strong>Objective</strong>: Identify specific issues or challenges customers may be facing with the new packaging and gather insights into their overall satisfaction with the changes.</li></ul><p>2. Reevaluating Marketing Strategies</p><ul><li>Data Mart’s marketing team should reassess their strategies to effectively communicate the benefits of sustainable packaging. This includes addressing any misconceptions or concerns customers may have about the environmental impact.</li><li><strong>Objective</strong>: Ensure that marketing materials clearly convey the positive aspects of sustainable packaging and alleviate any doubts or misunderstandings among the customers.</li></ul><p>3. Proactive Communication</p><ul><li>In future changes or implementations, Data Mart should communicate such alterations to customers in advance. Provide clear and concise information about the reasons behind the packaging changes and emphasize the benefits to both customers and the environment.</li><li><strong>Objective:</strong> Create transparency and build trust with customers by keeping them informed about upcoming changes.</li></ul><h4><strong>Conclusion</strong></h4><p>This thorough analysis has uncovered invaluable insights into Data Mart’s sales performance both before and after the implementation of sustainable packaging changes. The insights drawn from this analysis will play a crucial role in guiding the business towards sustained growth in the dynamic sector of online retail.</p><p>In Data we trust!!</p><p><a href="https://github.com/Diana-Injelwa/Case-Study-5">Check out the link to the SQL code on my GitHub</a></p><p><a href="https://www.mavenanalytics.io/project/11048">View Dashboard here</a></p><p>Follow me on</p><p><a href="https://twitter.com/Injelwa_">Twitter</a></p><p><a href="https://www.linkedin.com/in/diana-injelwa/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cb8c171d8c4" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/analyzing-the-impact-of-sustainable-practices-on-data-marts-sales-performance-5cb8c171d8c4">Analyzing the Impact of Sustainable Practices on Sales Performance</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL JOINS]]></title>
            <link>https://medium.com/@dianainjelwa/sql-joins-cfc29ff54ac6?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfc29ff54ac6</guid>
            <category><![CDATA[leftjoin]]></category>
            <category><![CDATA[innerjoin]]></category>
            <category><![CDATA[self-join]]></category>
            <category><![CDATA[right-join]]></category>
            <category><![CDATA[sql-joins]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Wed, 13 Sep 2023 09:58:02 GMT</pubDate>
            <atom:updated>2023-09-13T09:58:02.959Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introduction</h4><p>SQL joins are essential tools that enable data professionals to connect and consolidate information from multiple tables. As a Data Analyst, understanding how joins work is fundamental for extracting meaningful insights from your data. In this article, we will delve into the different types of SQL joins and demystify their applications. We will query data stored across multiple tables including;</p><ul><li>employee table which stores all the employee’s details</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*BOqmNnfsn03GKJlWXncqIw.png" /><figcaption>Employee table</figcaption></figure><ul><li>managers table which stores the manager’s details</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*718JBVWv4MJMTQxmt49Esg.png" /><figcaption>Managers table</figcaption></figure><ul><li>department table which stores the department’s details</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*hmjp1OfGqo98dyM1659qBQ.png" /><figcaption>Department table</figcaption></figure><ul><li>projects table which stores project’s details</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*yVMplkar6tVXO-rOH1KuOQ.png" /><figcaption>Projects table</figcaption></figure><ul><li>company table which stores details about the company</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*BOniy4Tj_irfyrm8c5OEpw.png" /><figcaption>Company table</figcaption></figure><ul><li>family table</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*cx8VnM1cy2dzTDW-KAWO5g.png" /><figcaption>Family table</figcaption></figure><h4><strong>INNER JOIN</strong></h4><p>An inner join returns only matching records present in both tables based on the specified join condition.</p><pre>/* Fetch the employee name and the department name they <br>belong to */<br>SELECT emp_name, dept_name<br>FROM employee e<br>INNER JOIN department d<br>ON e.dept_id = d.dept_id; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*h7Mo5bF97eSiPHSEMo5e6w.png" /><figcaption>Output</figcaption></figure><h4><strong>LEFT JOIN ( or LEFT OUTER JOIN)</strong></h4><p>A left join returns all rows from the left table and the matching rows from the right table. If there is no match in the right table, NULL values are returned for its columns. In simple terms, LEFT JOIN = INNER JOIN + any additional records from the left table.</p><pre>/* Fetch ALL the employee names and the department name<br>they belong to */<br>SELECT emp_name, dept_name<br>FROM employee e<br>LEFT JOIN department d<br>ON e.dept_id = d.dept_id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*MBezw9UL3uBbpc5sXBYIbQ.png" /><figcaption>Output</figcaption></figure><h4><strong>RIGHT JOIN (or RIGHT OUTER JOIN)</strong></h4><p>A right join returns all rows from the right table and the matching rows from the left table. If there is no match in the left table, NULL values are returned for its columns. i.e. RIGHT JOIN = INNER JOIN + any additional records from the right table</p><pre>/* Fetch ALL department names and their employees */ <br>SELECT emp_name, dept_name<br>FROM employee e<br>RIGHT JOIN department d<br>ON e.dept_id = d.dept_id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*dh0FbhT7mxP9yUPSEtsmgQ.png" /><figcaption>Output</figcaption></figure><h4><strong>FULL JOIN (or FULL OUTER JOIN)</strong></h4><p>A full join returns all rows when there is a match in either the left or the right table. If there is no match in one of the tables, NULL values are returned for the columns of the table without a match. Therefore, FULL OUTER JOIN = INNER JOIN + RIGHT JOIN + LEFT JOIN</p><p><strong>Note: In MySQL, union the results from a right join and left join since full join or full outer join keyword does not exist. When using UNION, it’s important to ensure that both SELECT statements retrieve the same columns with the same aliases.</strong></p><pre>/* Fetch ALL employee names and department names */<br>SELECT emp_name, dept_name<br>FROM employee e<br>RIGHT JOIN department d<br>ON d.dept_id = e.dept_id<br>UNION<br>SELECT e.emp_name, d.dept_name<br>FROM employee e<br>LEFT JOIN department d<br>ON d.dept_id = e.dept_id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*ZZkzk_YmqCMOypg9pp0vmw.png" /><figcaption>Output</figcaption></figure><h4><strong>CROSS JOIN( or CARTESIAN JOIN)</strong></h4><p>A cross join combines all rows from the first table with all rows from the second table, resulting in a Cartesian product. It does not require a join condition.</p><pre>/* Write a query to fetch the employee name and their department names<br>along with the company name and the company location corresponding<br>to each employee */<br>SELECT e.emp_name, d.dept_name, c.company_name, c.location<br>FROM employee e<br>INNER JOIN department d<br>ON e.dept_id = d.dept_id<br>CROSS JOIN company c;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*XV4Qhf2NnuL4iPdz28kAmA.png" /><figcaption>Output</figcaption></figure><h4><strong>SELF JOIN</strong></h4><p>A self join is used to join a table with itself. This is often used when dealing with hierarchical data or when you want to compare rows within the same table.</p><p><strong>Note: There’s no keyword as SELF JOIN in SQL. Therefore, use standard JOIN syntax with table aliases to differentiate between the two instances of the same table.</strong></p><pre>/* Write a query to fetch the child name and their age along with the parent<br>name and age */<br>SELECT<br>    child.name AS child_name,<br>    child.age AS child_age,<br>    parent.name AS parent_name,<br>    parent.age AS parent_age<br>FROM family AS child<br>JOIN family AS parent<br>ON child.parent_id = parent.member_id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*4pzrznVn18dbd0AFmaO3uw.png" /><figcaption>Output</figcaption></figure><h4><strong>Conclusion</strong></h4><p>Joins are a powerful feature of SQL and allow data professionals to retrieve and analyze data from related tables in a database, enabling complex queries and data manipulation. The choice of which join type to use depends on the specific requirements of your query and the structure of your database.</p><p>Happy learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfc29ff54ac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[INDEX MATCH FUNCTION]]></title>
            <link>https://medium.com/@dianainjelwa/index-match-function-25c00e83a427?source=rss-dac709fc4208------2</link>
            <guid isPermaLink="false">https://medium.com/p/25c00e83a427</guid>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[index-match]]></category>
            <category><![CDATA[excel-function]]></category>
            <dc:creator><![CDATA[ Diana Injelwa]]></dc:creator>
            <pubDate>Tue, 12 Sep 2023 08:53:17 GMT</pubDate>
            <atom:updated>2023-09-12T08:53:17.538Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Introduction</strong></h4><p>In this article we will look at INDEX MATCH Excel function. Its a combination of two functions INDEX and MATCH. INDEX MATCH function in Excel is used to perform advanced lookup and retrieval of data from a table or range. Its primary purpose is to find a specific value within a range and then return a corresponding value from another column or range, based on certain criteria.</p><h4><strong>Arguments for INDEX MATCH</strong></h4><p><em>=INDEX(array,MATCH(lookup_value,lookup_array,[match_type])</em></p><ul><li>array: This is the range from which you want to retrieve data</li><li>lookup_value: The value that we are looking for</li><li>lookup_array: The range in which we want to find the value</li><li>match_type: The options for this argument are: -1 , 0 or 1. 0 for exact match, -1 and 1 for approximate match</li></ul><h4><strong>Key differences between VLOOKUP and INDEX MATCH</strong></h4><ul><li>VLOOKUP is primarily designed for vertical lookup, meaning it searches for a value in the leftmost column of a table and returns a corresponding value from a specified column. INDEX MATCH on the other hand can perform both vertical and horizontal lookups, making it more versatile.</li><li>VLOOKUP requires you to specify the column number from which to return the result, INDEX MATCH on the other hand does not have this limitation.</li><li>With VLOOKUP, the lookup value must always be in the leftmost column of the table you’re searching. INDEX MATCH does not have this restriction and can look up values in any column.</li></ul><h4><strong>Advantages of using INDEX MATCH</strong></h4><ul><li>INDEX MATCH can perform both vertical and horizontal lookups, allowing you to retrieve data from tables or ranges in any direction.</li><li>INDEX MATCH is more flexible since it does not require you to specify a static column number as VLOOKUP does. hence the formula will still work correctly even if the order of columns in your data changes.</li></ul><h4><strong>Conclusion</strong></h4><p>INDEX MATCH function is a valuable addition to any Data Analyst’s toolkit, enabling them to tackle complex data retrieval tasks with ease and precision. <a href="https://medium.com/@dianainjelwa/excel-interview-questions-394a7acb746c">Please take a moment to review my prior article, where I discussed the VLOOKUP function</a></p><p>Happy learning data nerds!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25c00e83a427" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>