<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Patrick Kinoti</title>
    <description>The latest articles on DEV Community by Patrick Kinoti (@patrickkinoti).</description>
    <link>https://dev.to/patrickkinoti</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3402784%2F6f076b98-4a50-4243-a33b-e6d3bed4adda.jpeg</url>
      <title>DEV Community: Patrick Kinoti</title>
      <link>https://dev.to/patrickkinoti</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/patrickkinoti"/>
    <language>en</language>
    <item>
      <title>Understanding the Differences Between Subqueries, CTEs, and Stored Procedures</title>
      <dc:creator>Patrick Kinoti</dc:creator>
      <pubDate>Mon, 08 Sep 2025 13:22:13 +0000</pubDate>
      <link>https://dev.to/patrickkinoti/understanding-the-differences-between-subqueries-ctes-and-stored-procedures-3b75</link>
      <guid>https://dev.to/patrickkinoti/understanding-the-differences-between-subqueries-ctes-and-stored-procedures-3b75</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Subqueries, CTEs, and stored procedures are three powerful tools that shape how we write and optimize SQL. At first glance they may seem alike, but each serves a unique purpose, and understanding their distinctions can help you choose the right approach for your needs, i.e Subqueries help nest logic, CTEs improve clarity and organization, while stored procedures package logic for reuse and efficiency.&lt;/p&gt;

&lt;h5&gt;
  
  
  Subqueries
&lt;/h5&gt;

&lt;p&gt;A subquery is a query nested inside another SQL query. It is enclosed in parentheses and provides a result that the main query can use—either as a value, a set of rows, or as part of a condition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT first_name, last_name
FROM employees e
WHERE salary &amp;gt; (
    SELECT AVG(salary) 
    FROM employees 
    WHERE department_id = e.department_id)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Outer query: selects first_name and last_name from employees table (e).&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Condition: keeps only employees whose salary is greater than the result of the subquery.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Subquery: calculates the average salary of employees in the same department (department_id = e.department_id).&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Correlation: the subquery depends on the outer query (e.department_id).&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  CTE (Common Table Expression)
&lt;/h5&gt;

&lt;p&gt;A CTE is a temporary, named result set—like an inline view—that exists only during query execution, defined using the WITH clause. They enhance readability by breaking up complex SQL, eliminate repetitive subqueries, and support recursive data retrieval. Used for Structuring complex queries, handling hierarchical or recurring logic, and avoiding duplication&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;with ranking_customers as (
    select orders.customer_id,SUM(orders.quantity) as total_quantity,
    row_number()over(order by sum(orders.quantity)desc  ) as customer_rank
    from orders 
    group by orders.customer_id)
select customers.first_name,customers.last_name,ranking_customers.total_quantity, ranking_customers.customer_rank
from customers 
join ranking_customers on customers.customer_id=ranking_customers.customer_id   
order by ranking_customers.customer_rank;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  CTE (ranking_customers)
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Groups orders by customer_id.&lt;/em&gt;
-_ Calculates SUM(quantity) = total items ordered per customer._&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Assigns rank using ROW_NUMBER() (highest quantity = rank 1).&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Main query
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Joins customers table with the CTE on customer_id.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Selects customer’s first &amp;amp; last name, total quantity, and rank.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Orders the result by customer_rank.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Stored Procedure
&lt;/h5&gt;

&lt;p&gt;A stored procedure is a precompiled set of SQL statements stored on the database server, executed by calling its name. It can include logic, parameters, and multiple queries, offering reusability and performance benefits for repeated tasks, but it’s more complex to maintain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE PROCEDURE GetCropYieldByCounty(IN crop_name VARCHAR(50))
BEGIN
    SELECT county, SUM(yield_tons) AS total_yield
    FROM crops
    WHERE crop = crop_name
    GROUP BY county
    ORDER BY total_yield DESC;
ENd;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Procedure name: GetCropYieldByCounty&lt;/li&gt;
&lt;li&gt;Input: crop_name (the crop to check)&lt;/li&gt;
&lt;li&gt;Action: Selects each county and calculates SUM(yield_tons) for that crop&lt;/li&gt;
&lt;li&gt;Groups results by county and sorts them in descending order of yield&lt;/li&gt;
&lt;li&gt;Example: CALL GetCropYieldByCounty('Maize'); → shows maize yields per county&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Comparison of Subqueries, CTEs, and Stored Procedures
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Subquery&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;CTE&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Stored Procedure&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Inline query inside another query, used once for filtering or aggregation.&lt;/td&gt;
&lt;td&gt;Temporary named query using &lt;code&gt;WITH&lt;/code&gt;, simplifies and can be reused within one query.&lt;/td&gt;
&lt;td&gt;Saved SQL program stored in the DB, reusable, handles complex logic.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;SELECT * FROM crops WHERE yield_tons &amp;gt; (SELECT AVG(yield_tons) FROM crops);&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;WITH cte AS (SELECT * FROM crops) SELECT * FROM cte;&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Example:&lt;/strong&gt; &lt;code&gt;CALL GetCropYieldByCounty('Maize');&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>luxdevhq</category>
    </item>
    <item>
      <title>EXCEL'S ROLE IN PREDICTIVE ANALYSIS AND BUSINESS DECISIONS.</title>
      <dc:creator>Patrick Kinoti</dc:creator>
      <pubDate>Mon, 11 Aug 2025 18:01:45 +0000</pubDate>
      <link>https://dev.to/patrickkinoti/excels-role-in-predictive-analysis-and-business-decisions-4clm</link>
      <guid>https://dev.to/patrickkinoti/excels-role-in-predictive-analysis-and-business-decisions-4clm</guid>
      <description>&lt;h3&gt;
  
  
  INTRODUCTION
&lt;/h3&gt;

&lt;p&gt;In today’s data-driven world, making informed business decisions is essential for growth and sustainability. While many advanced analytics platforms exist, Microsoft Excel remains one of the most widely used tools for predictive analysis and decision-making — thanks to its accessibility, flexibility, and built-in analytical capabilities.&lt;/p&gt;

&lt;h3&gt;
  
  
  WHAT IS PREDICTIVE ANALYSIS?
&lt;/h3&gt;

&lt;p&gt;Predictive analysis is the use of historical data, statistical algorithms, and machine learning techniques to forecast future outcomes. It enables businesses to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Anticipate market trends&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand customer behavior&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Optimize operations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduce risks&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj813psel5se9f12p4p1q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj813psel5se9f12p4p1q.jpg" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  WHY IS EXCEL STILL RELEVANT?
&lt;/h3&gt;

&lt;p&gt;Despite the rise of complex data tools like Python, R, and Power BI, Excel plays a foundational role in many organizations due to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ease of use – No coding required&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Familiar interface – Widely adopted by professionals&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Built-in functions – For regression, forecasting, and trend analysis&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compatibility – Integrates easily with other software and data sources&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  EXCEL TOOL FOR PREDICTING ANALYSIS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Forecast Sheet -   Predicts future values based on past data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Trendlines -   Shows data trends and future projections in charts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Regression (Data Analysis ToolPak) -   Analyzes relationships between   variables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What-If Analysis -   Tests different scenarios and outcomes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Goal Seek -   Finds the input needed to reach a target result.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Solver -   Optimizes results based on conditions (e.g., maximize profit).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PivotTables -   Summarizes and analyzes large data sets.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  REAL-WORLD BUSINESS APLICATION
&lt;/h3&gt;

&lt;p&gt;Use Case Excel Predictive Feature Used&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sales Forecasting -   Forecast Sheet, Trendlines&lt;/li&gt;
&lt;li&gt;Budget Planning   -    What-If Analysis, Goal Seek&lt;/li&gt;
&lt;li&gt;Customer Churn Prediction -   Regression Analysis, PivotTables&lt;/li&gt;
&lt;li&gt;Inventory Management -   Data Tables, Forecasting&lt;/li&gt;
&lt;li&gt;Pricing Strategy -    Solver, Scenario Manager&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4rqblwd5tfo7e8jnit3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa4rqblwd5tfo7e8jnit3.jpg" alt=" " width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ANDVANTAGES OF USING EXCEL FOR PREDICTIVE ANALYSIS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Low barrier to entry (no specialized software needed)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Widely available across organizations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Great for prototyping models before moving to more complex tools&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy to visualize data and share insights&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  LIMITATION
&lt;/h3&gt;

&lt;p&gt;While Excel is powerful, it's not a substitute for full-scale data science tools in complex scenarios. Its limitations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Limited processing power for big data &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No built-in machine learning models&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Risk of manual errors&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  FINAL THOUGHT
&lt;/h3&gt;

&lt;p&gt;Excel remains an essential tool in the business analytics toolkit — especially for small to mid-sized businesses and early-stage analysts. With the right use of its predictive and analytical features, Excel can significantly aid in data-driven decision-making.&lt;/p&gt;

&lt;p&gt;🌟 Excel may not be a crystal ball, but in the hands of a skilled user, it's close.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
