Skip to main content

Posts

Pinned Post

Part II: Retrieving Data Chapter 6: Subqueries and Derived Tables

  Chapter 6: Subqueries and Derived Tables Complex business questions often require breaking problems into smaller, composable parts. SQL subqueries and derived tables—sometimes called inline views—offer a clean way to nest queries, test membership, and encapsulate logic. In this chapter, you’ll learn how to: Write scalar and correlated subqueries Use EXISTS and NOT EXISTS for efficient membership tests Create derived tables for readability and modularity Nest queries to filter data based on other query results By the end, you’ll tackle multi-step analyses with maintainable, self-documenting SQL. 1. Understanding Subqueries A subquery is a query enclosed in parentheses that returns data to the outer (parent) query. There are two main flavors: Scalar subqueries return a single value. Correlated subqueries reference columns from the outer query and re-execute per row. 1.1 Scalar Subqueries Use scalar subqueries when you need a single aggregated or computed value: sql SELECT o....
Recent posts

Lesson 3.5 – Text Functions (LEFT, RIGHT, MID, LEN, CONCAT)

Lesson 3.5 – Text Functions (LEFT, RIGHT, MID, LEN, CONCAT) Text functions help you extract, combine, and analyze text values in Excel. They are essential for cleaning data, preparing reports, and working with names, codes, product IDs, and imported datasets. In questa lezione impari cinque funzioni fondamentali: LEFT , RIGHT , MID , LEN e CONCAT . 1. LEFT – Extract Characters from the Left Syntax: =LEFT(text, number_of_characters) Example: =LEFT("ProductA", 7) Result: Product LEFT is useful for extracting prefixes, codes, or the first part of a string. 2. RIGHT – Extract Characters from the Right Syntax: =RIGHT(text, number_of_characters) Example: =RIGHT("AB12345", 5) Result: 12345 RIGHT is ideal for extracting numeric codes, suffixes, or final characters. 3. MID – Extract Characters from the Middle Syntax: =MID(text, start_position, number_of_characters) Example: =MID("AB-2024-IT", 4, 4) R...

Lesson 3.4 – Counting Functions (COUNT, COUNTA, COUNTBLANK)

Lesson 3.4 – Counting Functions (COUNT, COUNTA, COUNTBLANK) Counting data is one of the most common tasks in Excel. Whether you are analyzing sales, checking how many entries are missing, or counting how many values are valid, Excel provides simple functions to help you. In this lesson, you will learn three essential counting functions: COUNT , COUNTA , and COUNTBLANK . 1. COUNT – Count Numbers Only COUNT counts how many cells contain numeric values. Syntax: =COUNT(range) Example: =COUNT(A2:A10) COUNT ignores text, empty cells, and errors. Use it when you want to count numeric entries only . 2. COUNTA – Count Non‑Empty Cells COUNTA counts all non‑empty cells, regardless of content. Syntax: =COUNTA(range) Example: =COUNTA(B2:B10) COUNTA counts: Numbers Text Dates Logical values (TRUE/FALSE) Errors Use COUNTA when you want to know how many cells contain any type of data . 3. COUNTBLANK – Count Empty Ce...

Lesson 3.3 – Math Functions (SUM, AVERAGE, MIN, MAX)

Lesson 3.3 – Math Functions (SUM, AVERAGE, MIN, MAX) Excel includes built‑in functions that make calculations faster, easier, and more accurate. In this lesson, you will learn four essential math functions used worldwide in business, finance, and data analysis: SUM , AVERAGE , MIN , and MAX . 1. What Is a Function? A function is a predefined formula that performs a specific calculation. All functions follow this structure: =FUNCTION_NAME(arguments) Example: =SUM(A1:A10) Functions save time and reduce errors compared to writing formulas manually. 2. SUM – Add Values SUM adds numbers in a range of cells. Syntax: =SUM(range) Example: =SUM(B2:B10) SUM is ideal for totals, budgets, sales, and any numeric aggregation. 3. AVERAGE – Calculate the Mean AVERAGE calculates the arithmetic mean of a group of numbers. Syntax: =AVERAGE(range) Example: =AVERAGE(C2:C10) Use AVERAGE to analyze performance, scores, or trends. ...

Part II: Retrieving Data Chapter 5: Aggregation and Grouping

  Part II: Retrieving Data Chapter 5: Aggregation and Grouping Summarizing data is essential when you need high-level insights from large tables. Aggregate functions let you collapse detailed rows into single metrics—like totals, averages, or counts. Grouping then partitions those rows into buckets for segmented analysis. In this chapter, we’ll explore: Core aggregate functions: COUNT , SUM , AVG , MIN , MAX Using GROUP BY to create logical buckets Filtering groups with HAVING Handling NULL values within aggregations Practical examples for generating charts and reports 1. Aggregation Functions Overview Aggregate functions process multiple rows to produce a single summary value. They ignore row-level granularity and calculate metrics across a set: COUNT(expr) returns the number of non- NULL values or * for all rows SUM(expr) adds numeric values across rows AVG(expr) computes the average of numeric values MIN(expr) finds the smallest value MAX(expr) finds the largest value E...

Lesson 3.2 – Relative vs Absolute References

Lesson 3.2 – Relative vs Absolute References When you copy a formula in Excel, the cell references inside it may change automatically. This behavior is extremely powerful, but only if you understand how it works. In this lesson, you will learn the difference between relative , absolute , and mixed references. 1. What Are Cell References? A cell reference tells Excel where to find the data used in a formula. Examples: A1 → column A, row 1 B5 → column B, row 5 C10 → column C, row 10 When you copy a formula, Excel may adjust these references automatically. 2. Relative References (A1) Relative references change when a formula is copied to another cell. This is the default behavior in Excel. Example: =A1 + B1 If you copy this formula from row 1 to row 2, it becomes: =A2 + B2 Excel “moves” the references based on the direction of the copy. 3. Absolute References ($A$1) Absolute references do not change when copi...