Catalogue · First steps in Python and SQL, with AI

Count and add up in SQL

You count sales and total them by store, in SQL.

JupyterLiteIntermediate0:19Capsule 10 of 12
SkillKapsul

Space: play · ← →: 5 seconds · M: sound · F: full screen

The steps

The exact sequence, in order.

  1. 01

    Type SELECT store, COUNT(*) AS n, SUM(amount) AS total

  2. 02

    Then FROM sales and GROUP BY store

  3. 03

    Then ORDER BY total DESC LIMIT 3;

  4. 04

    Shift + Enter: Lyon Croix-Rousse, 42 sales, 2016.0. The same numbers as with Python.

The habit to keep

AS gives each calculated column a clear name.

Related capsules

You might also like

Newsletter

Monday's capsule

One skill a week, straight to your inbox. The easiest way to keep learning without thinking about it.

No spam, no reselling. One-click unsubscribe.

Your data stays in the EU. Never sold.

SkillKapsul