DATASCI 350 - Data Science Computing

Lecture 26 - Revision: Scaling, SQL and Containers

Danilo Freire

Department of Data and Decision Sciences
Emory University

Hello, everyone! 😊

Where we are

  • Eight modules
    • Introduction: how a computer stores and runs your code
    • Command line and version control: Bash, Git, GitHub
    • Reproducible research: Quarto and project structure
    • AI-assisted programming: local models, APIs, RAG
    • Cloud computing: EC2 and S3
    • Getting data from the web: APIs, JSON, a saved snapshot
    • Scaling and performance: joblib, Dask, DuckDB
    • Containers: environments and Docker
  • Today we revise the last two modules
  • Quiz 05 covers Lectures 21, 22, 23 and 25
  • The final project is due on the last day of class

Lecture overview

What we will cover today

1. Scaling and performance

  • Parallel tools, Big O, Amdahl’s law, Dask

2. SQL revision

  • Query order, WHERE and HAVING, COUNT, joins

3. SQL practice

  • Five queries: guess the output, then run them

4. Containers

  • Pinning an environment
  • The project Dockerfile and docker run
  • The project checklist and mixed groups

5. Quiz 05 preparation

  • Likely questions from each lecture
  • Five Dockerfile questions to practise

Scaling and performance

Parallel work and its tools

  • Serial: one line after another
  • Parallel: independent tasks at the same time, on several cores
  • Embarrassingly parallel: the tasks share nothing and need no result from each other
  • Parallelise only independent tasks big enough to justify a worker
from joblib import Parallel, delayed

def bar(x):
    return x * x

Parallel(n_jobs=-1)(delayed(bar)(x) for x in range(6))
# [0, 1, 4, 9, 16, 25]
  • Four workers never give a full 4Γ— speed-up: starting them takes time
Your task Tool
Number crunching ProcessPoolExecutor
Downloading many URLs ThreadPoolExecutor
sklearn, numeric loops joblib (n_jobs=-1)
Bigger than RAM Dask
  • CPU-bound work keeps the processor busy, so use processes
  • I/O-bound work waits for the network or disk, so use threads
  • concurrent.futures ships with Python, so it needs no install

Big O and Amdahl’s law

  • Big O: how the runtime grows with the input size n
  • When n doubles, the runtime stays the same for O(1), doubles for O(n) and quadruples for O(nΒ²)
  • N cores turn O(n) into O(n/N + overhead), but the class stays the same
  • Poor candidates for parallelism:
    • Steps that need the result of the step before
    • Tasks that share a variable, like a running total
    • Tasks limited by the disk or memory
  • Amdahl’s law: the serial share \(s\) limits the speed-up

  • \(\text{speedup} = \dfrac{1}{s + p/N}\)

    • speedup: times faster than on one core
    • \(s\): share of the runtime that must run serially
    • \(p = 1 - s\): share that can run in parallel
    • \(N\): number of cores
    • \(p/N\): the parallel share, split across the cores
  • 90% parallel on 8 cores: 1 / (0.1 + 0.9/8) = 1 / 0.2125 = 4.7x

  • The maximum speed-up is \(1/s\): 10Γ— here, 2Γ— if half the program is serial

Dask, and which tool when

  • Dask has lazy versions of NumPy arrays, pandas DataFrames and your own functions (delayed)
  • Lazy: Dask builds a task graph and runs nothing until .compute()
  • .persist() keeps a small result in memory
  • Dask chunks the data, so it can be bigger than your RAM
  • The dashboard at localhost:8787 shows the tasks live
  • On data that fits in memory, Dask can be slower than pandas
  • Parquet files are much smaller than the same data in CSV
  • Mean value by indicator and decade, on 200,681,600 rows, Apple M5 laptop:
pandas Dask DuckDB
9.65 s 5.39 s 0.53 s
  • DuckDB reads only the columns it needs, and uses every core
Your situation Reach for
Fits in RAM, exploring, plotting pandas
One large file on one machine DuckDB
Bigger than the machine, or a cluster Dask

SQL revision

How a query runs

  • WHERE filters rows before grouping, and HAVING filters groups after
  • No aggregate can go in WHERE, because the groups do not exist yet
  • Every SELECT column is in GROUP BY or inside an aggregate
SELECT country,
       ROUND(AVG(value), 0) AS mean_gdp
FROM wdi
WHERE indicator = 'gdp_per_capita'
  AND year >= 2010
GROUP BY country
HAVING AVG(value) > 60000
ORDER BY mean_gdp DESC
LIMIT 5
  • WHERE year >= 2010 drops old rows
  • HAVING AVG(value) > 60000 drops poorer countries

COUNT(*) and COUNT(value)

  • COUNT(*) counts rows, and COUNT(value) counts rows with a value
  • COUNT(*) - COUNT(value) gives the number of missing values
  • AVG, SUM, MIN and MAX skip missing values without warning
  • If every value in a group is NULL, AVG returns NULL
  • value = NULL never matches. Test with IS NULL or IS NOT NULL
SELECT year,
       COUNT(*) AS n_rows,
       COUNT(value) AS with_value,
       COUNT(*) - COUNT(value) AS missing
FROM wdi
WHERE indicator = 'internet_users_pct'
  AND year IN (1990, 2000, 2020)
GROUP BY year
ORDER BY year
  • n_rows stays the same each year, because the panel has a row for every country
  • with_value falls when countries stop reporting, so missing rises

Three joins

  • INNER JOIN drops unmatched rows without warning
  • LEFT JOIN keeps every row of the left table
  • FULL OUTER JOIN keeps every row of both tables
  • ON names the column that links the two tables
  • Check the row count after every join
  • To choose, ask which table must survive whole

SQL practice

The setup

Run this once

import duckdb

duckdb.sql("""
    CREATE OR REPLACE VIEW wdi AS
    SELECT * FROM
    '../lecture-19/data/wdi_panel.parquet'
""")

duckdb.sql("SELECT COUNT(*) AS n_rows FROM wdi")
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ n_rows β”‚
β”‚ int64  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  59024 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • The panel from Module 06 has 59,024 rows and five columns: country, iso3, indicator, year, value
  • Eight indicators, including gdp_per_capita, life_expectancy, co2_per_capita and internet_users_pct
  • Five short queries follow. Guess each answer before we run it
  • A longer exercise to practise at home: Appendix 09

Question 1 of 5

SELECT country,
       ROUND(value, 1) AS co2_pc
FROM wdi
WHERE indicator = 'co2_per_capita'
  AND year = 2020
ORDER BY value DESC
LIMIT 3

How many rows and columns come back?

What changes without DESC?

What changes without LIMIT 3?

Answer: Appendix 01

Question 2 of 5

SELECT country,
       ROUND(value, 1) AS co2_pc
FROM wdi
WHERE indicator = "co2_per_capita"
  AND year = 2020
ORDER BY value DESC
LIMIT 3

Line 4 changed from Question 1: look at the quotes

What happens when you run it?

Answer: Appendix 02

Question 3 of 5

SELECT country,
       ROUND(AVG(value), 1) AS mean_internet
FROM wdi
WHERE indicator = 'internet_users_pct'
  AND year >= 2015
  AND AVG(value) > 95
GROUP BY country

Does this query run?

If not, how do you fix it?

Answer: Appendix 03

Question 4 of 5

SELECT COUNT(*) AS n_rows,
       COUNT(value) AS with_value
FROM wdi
WHERE indicator = 'internet_users_pct'
  AND year = 2020

Can with_value ever be bigger than n_rows?

When are the two equal?

Answer: Appendix 04

Question 5 of 5

gdp

iso3 gdp_pc
BRA 8435
IND 1807
JPN 35363

life

iso3 life_exp
BRA 74.5
IND 70.2
USA 77.0
SELECT g.iso3, gdp_pc, life_exp
FROM gdp AS g
INNER JOIN life AS l
  ON g.iso3 = l.iso3

How many rows come back?

And with LEFT JOIN? With FULL OUTER JOIN?

Answer: Appendix 05

Containers and Docker

Python environments

# Create and activate (macOS, Linux)
python3 -m venv .venv
source .venv/bin/activate

# Install, then record exact versions
pip install pandas duckdb
pip freeze > requirements.txt

# Rebuild on another machine
pip install -r requirements.txt
  • An environment is a folder with its own Python and packages, separate from the system
  • pip freeze lists every package with an == pin, dependencies included
  • == pins one exact version, and >= accepts any newer one
Tool File you commit Key commands
venv + pip requirements.txt pip freeze, pip install -r
conda environment.yml conda env export --from-history
uv pyproject.toml, uv.lock uv add, uv sync, uv export
  • pip freeze inside conda writes @ file:/// paths that break on other machines
  • More on uv: Appendix 08

Whatever tool you use, submit requirements.txt with == pins, because the Dockerfile reads it

The project Dockerfile

# 1. Base image
FROM ubuntu:24.04

# 2. Build-time settings
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-c"]

# 3. System packages
RUN apt-get update && apt-get install -y [...]

# 4. Quarto
RUN ARCH=$(dpkg --print-architecture) && [...]

# 5. Python environment
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt /project/requirements.txt
RUN pip install --no-cache-dir -r /project/requirements.txt

# 6. Project files
WORKDIR /project
COPY . /project

# 7. Default command
ENV QUARTO_PYTHON=/opt/venv/bin/python
CMD ["bash", "-c", "quarto render report.qmd && [...]"]
  • FROM pins the base image
  • DEBIAN_FRONTEND=noninteractive stops apt asking questions
  • dpkg --print-architecture picks the arm64 or amd64 Quarto .deb
  • Packages go in a venv at /opt/venv, because Ubuntu protects its own Python
  • COPY requirements.txt comes first, so editing the report keeps pip install cached
  • RUN runs a command while the image builds
  • ENV sets a variable that later steps and the container keep
  • WORKDIR sets the folder where later commands run, and creates it if needed

Building and running the image

  • An image is a read-only template, built from a Dockerfile
  • A container is a running image
  • A registry, like Docker Hub, stores images
docker build -t datasci350-project .

docker run --rm \
  -v "$(pwd)/output:/project/output" \
  datasci350-project
  • Editing the report rebuilds in seconds, but editing requirements.txt reruns pip
  • -t names the image
  • --rm deletes the container when it exits
  • -v host:container links a laptop folder to a container folder
  • Without -v, the report disappears with the container
  • -p host:container maps ports. The project needs only -v
  • .dockerignore keeps .git, caches and outputs out of the image
  • OrbStack, Podman and Colima accept the same commands

The project checklist

  • Commit data/raw/, and check with git ls-files data/raw
  • Pin every package with ==, to a version on PyPI
  • Test from a fresh clone in an empty folder
  • After the run, ls output should show a fresh report
  • My machine has only Docker: no Python, Quarto or packages
  • Common errors:
    • Data not committed: the build works, but the run fails with IOException: No files found
    • A pin that does not exist: pip stops the build
    • No -v: the report disappears with the container
  • Where to find help:

Working in a mixed group

  • The container runs Linux, whatever laptop you use
  • Match file name case: by default, macOS treats Data.csv and data.csv as one file, but Linux does not
  • Keep Linux line endings: do not delete the starter’s .gitattributes
  • On Windows, clone into your WSL home folder (~/), not /mnt/c/
  • Turn on WSL integration in Docker Desktop, and run every command in the WSL terminal
  • Each member builds their own image from the shared repository
  • An image built on an Apple Silicon Mac does not run on most Windows laptops
  • You never push an image: I build mine from your repository
  • The same advice is in the starter’s README.md

Quiz 05 and the project

What to expect

  • Lecture 21: parallel computing
    • Choose a tool for a task, and say why
    • Decide whether a function is embarrassingly parallel
    • Apply Amdahl’s law to the numbers given
  • Lecture 22: SQL with DuckDB
    • Say what a query returns
    • Fix an aggregate in WHERE
    • Count the rows a join returns, and say what COUNT does with NULLs
  • Lecture 23: environments and containers
    • Match venv, conda and uv to their files
    • Explain what pip freeze writes and what == means
    • Define image, container and registry
  • Lecture 25: Docker
    • Say what a Dockerfile block does
    • Explain why COPY requirements.txt comes before COPY .
    • Say what happens to the report without -v

Read this Dockerfile

FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y [...]

RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

COPY requirements.txt /project/requirements.txt
RUN pip install --no-cache-dir -r \
    /project/requirements.txt

WORKDIR /project
COPY . /project

CMD ["bash", "-c", "quarto render report.qmd"]
  1. What does FROM ubuntu:24.04 pin, and why do we avoid latest?
  2. What does WORKDIR /project do, and why does CMD need it?
  3. What does ENV PATH="/opt/venv/bin:$PATH" change?
  4. Which line reruns if you edit report.qmd, and which if you edit requirements.txt?
  5. What happens to output/report.html if you run the container without -v?

Answers: Appendix 07

Summary

What to revise

  • Embarrassingly parallel: tasks that share nothing and need no result from each other
  • Big O: parallelism divides the time, but the class stays the same
  • Amdahl’s law: \(\text{speedup} = 1/(s + p/N)\)
  • pandas for data that fit in RAM, DuckDB for one large file
  • Dask runs nothing until .compute()
  • Query order: FROM, WHERE, GROUP BY, HAVING, SELECT
  • WHERE filters rows, and HAVING filters groups
  • COUNT(*) counts rows, and COUNT(value) skips NULLs
  • A LEFT JOIN keeps every row of the left table
  • requirements.txt with == pins, whatever tool wrote it
  • Image, container, registry, and -v to keep the report

Before we finish

  • Thank you for a great semester! πŸ₯³πŸŽ‰
    • You went from cd to building a whole Linux container with Docker
  • Quiz 05 is on Thursday, 3 December
  • 8 December: Q&A and project work time, no lecture
  • Test your container from a fresh clone now, while you can still fix it
  • Email me if a topic is unclear, and we can meet in office hours
  • Please fill in the course evaluation. I read every comment 😊

Thank you very much! πŸ™

Appendix

Appendix 01: Answer to Question 1

duckdb.sql("""
    SELECT country,
           ROUND(value, 1) AS co2_pc
    FROM wdi
    WHERE indicator = 'co2_per_capita'
      AND year = 2020
    ORDER BY value DESC
    LIMIT 3
""")
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ country β”‚ co2_pc β”‚
β”‚ varchar β”‚ double β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Palau   β”‚   71.7 β”‚
β”‚ Qatar   β”‚   41.3 β”‚
β”‚ Bahrain β”‚   25.0 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • 3 rows and 2 columns: country and co2_pc
  • Without DESC, the sort is ascending, so the three lowest emitters come back
  • Without LIMIT 3, every country comes back: 217 rows, 14 of them with NULL
  • ROUND(value, 1) creates a new column, and AS co2_pc names it

Back to Question 1

Appendix 02: Answer to Question 2

Binder Error: Referenced column "co2_per_capita" not found in FROM clause!
Candidate bindings: "country", "year", "indicator"
  • The query fails with a Binder Error
  • Double quotes mean a column name, so DuckDB looks for a column called co2_per_capita
  • Text goes in single quotes: 'co2_per_capita'

Back to Question 2

Appendix 03: Answer to Question 3

Binder Error: WHERE clause cannot contain aggregates!
duckdb.sql("""
    SELECT country,
           ROUND(AVG(value), 1) AS mean_internet
    FROM wdi
    WHERE indicator = 'internet_users_pct'
      AND year >= 2015
    GROUP BY country
    HAVING AVG(value) > 95
    ORDER BY mean_internet DESC
    LIMIT 3
""")
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ country β”‚ mean_internet β”‚
β”‚ varchar β”‚    double     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Iceland β”‚          98.7 β”‚
β”‚ Bahrain β”‚          98.4 β”‚
β”‚ Bermuda β”‚          98.2 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • It fails: WHERE runs before GROUP BY, so the averages do not exist yet
  • The condition on the group moves to HAVING
  • The condition on year stays in WHERE, because it tests rows
  • 13 countries pass. ORDER BY and LIMIT 3 show the top three

Back to Question 3

Appendix 04: Answer to Question 4

duckdb.sql("""
    SELECT COUNT(*) AS n_rows,
           COUNT(value) AS with_value
    FROM wdi
    WHERE indicator = 'internet_users_pct'
      AND year = 2020
""")
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ n_rows β”‚ with_value β”‚
β”‚ int64  β”‚   int64    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    217 β”‚        184 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • COUNT(*) counts every row, and COUNT(value) skips NULLs
  • So with_value is never bigger, and it equals n_rows only when there are no NULLs
  • Here 33 of the 217 rows have no value
  • AVG(value) would use only the 184 values, without a warning

Back to Question 4

Appendix 05: Answer to Question 5

duckdb.sql("""
    SELECT g.iso3, gdp_pc, life_exp
    FROM gdp AS g
    LEFT JOIN life AS l
      ON g.iso3 = l.iso3
    ORDER BY g.iso3
""")
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  iso3   β”‚ gdp_pc  β”‚ life_exp β”‚
β”‚ varchar β”‚ double  β”‚  double  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ BRA     β”‚  8435.0 β”‚     74.5 β”‚
β”‚ IND     β”‚  1807.0 β”‚     70.2 β”‚
β”‚ JPN     β”‚ 35363.0 β”‚     NULL β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • INNER JOIN: 2 rows, because only Brazil and India are in both tables
  • LEFT JOIN: 3 rows, every row of gdp, with NULL for Japan’s life_exp
  • FULL OUTER JOIN: 4 rows, adding the US with NULL for gdp_pc
  • Check the row count after every join

Back to Question 5

Appendix 06: Checking your container

git clone <your repo url> fresh-test
cd fresh-test
docker build -t datasci350-project .
docker run --rm \
  -v "$(pwd)/output:/project/output" \
  datasci350-project
open output/report.html
  • The machine has Docker installed and nothing else: no Python, no Quarto, no packages
  • The build has internet, but the run is promised none
  • Check that the snapshot is committed:
git ls-files data/raw

Appendix 07: Answers to the Dockerfile questions

  1. FROM ubuntu:24.04 pins one Ubuntu release
    • latest meant 24.04 last year and 26.04 today, so it breaks reproducibility
  2. WORKDIR /project makes /project the folder where later commands run, and creates it if needed
    • CMD runs quarto render report.qmd from there, so Quarto finds the report
  3. ENV PATH="/opt/venv/bin:$PATH" puts /opt/venv/bin first, so python and pip mean the venv’s copies
  1. Editing report.qmd rebuilds from COPY . /project, so pip stays cached
    • Editing requirements.txt reruns pip and every step after it
  2. Without -v, the report renders inside the container
    • --rm then deletes the container, and the report with it

Back to the questions

Appendix 08: uv in more detail

uv init l23-uv-demo --python 3.14
cd l23-uv-demo
uv add polars requests

Resolved 8 packages in 279ms
Installed 7 packages in 8ms
 + polars==2.1.0
 [...]
 + requests==2.34.2

uv sync
Resolved 8 packages in 2ms

uv run python -c \
  "import polars; print(polars.__version__)"
2.1.0
  • uv: a fast package manager from Astral
  • uv add installs a package and records it
  • uv sync rebuilds the environment from the lock file
  • uv run runs code with no activate
  • pyproject.toml: your direct dependencies
  • uv.lock: exact versions of every package
  • Commit both files
  • uv export --format requirements-txt --no-hashes > requirements.txt writes the file the Dockerfile reads

Back to Python environments

Appendix 09: Practice exercise

Which countries have been the most connected since 2015?

  1. Run the setup cell so the wdi view exists
  2. Keep only the rows for internet_users_pct
  3. Keep only the years from 2015 onwards
  4. Report one row per country
  5. Count how many years have a number in value, and call it n_years
  6. Compute the mean of value, rounded to one decimal, as mean_internet
  7. Keep the countries with at least 5 years of data and a mean above 95
  8. Sort by the mean, highest first, and return five rows

Hints:

  • The filter on year and the two filters on the group go in different clauses
  • COUNT(*) would pass every country, so use COUNT(value) for the five years
  • Five countries come back, all above 97%

Solution: Appendix 10

Appendix 10: Solution to the practice exercise

duckdb.sql("""
    SELECT country,
           COUNT(value) AS n_years,
           ROUND(AVG(value), 1) AS mean_internet
    FROM wdi
    WHERE indicator = 'internet_users_pct'
      AND year >= 2015
    GROUP BY country
    HAVING COUNT(value) >= 5
       AND AVG(value) > 95
    ORDER BY mean_internet DESC
    LIMIT 5
""")
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  country   β”‚ n_years β”‚ mean_internet β”‚
β”‚  varchar   β”‚  int64  β”‚    double     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Iceland    β”‚       9 β”‚          98.7 β”‚
β”‚ Bahrain    β”‚       9 β”‚          98.4 β”‚
β”‚ Luxembourg β”‚       9 β”‚          97.9 β”‚
β”‚ Qatar      β”‚       9 β”‚          97.8 β”‚
β”‚ Denmark    β”‚       9 β”‚          97.5 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • WHERE filters rows, and both HAVING conditions test the group
  • COUNT(value) is 9 for these countries: every year from 2015 to 2023
  • COUNT(*) would be 9 for every country, even those with no values
  • ORDER BY can use mean_internet, the alias from SELECT

Back to the exercise