Repaso
EspaƱol

Which query counts users per country?

Options

  1. SELECT country, COUNT(*) FROM users GROUP BY country; (Correct option)
  2. SELECT COUNT(country) FROM users GROUP BY *;
  3. SELECT country FROM users COUNT BY country;
  4. SELECT * FROM users GROUP BY COUNT(country);

Answer

SELECT country, COUNT(*) FROM users GROUP BY country;

Why

GROUP BY country puts rows with the same country together into groups.

COUNT(*) then counts the rows inside each group.

The result has one row per country, e.g. ('Peru', 120), ('Spain', 85).

Remember

GROUP BY + COUNT = counts per category.

Key terms

Practice this question in Repaso