>_ IzzyLab

Hands-on task

This task is step 5 of the course “SQL with SQLite”

SQLite: revenue per category (GROUP BY)

easy~5 min

The database /root/shop.db has a table sales(id, category, amount). Compute the total revenue for each category and write the result to /root/out.txt in the format category|amount (one category per line).

What you'll practise:
  • sqlite3
  • group by
  • aggregate functions
  • sum
  • grouping

Topic breakdown

Aggregation collapses a set of rows into a single value. GROUP BY splits a table into groups by the value of a given column, and an aggregate function (SUM, COUNT, AVG, etc.) computes a total within each group separately. The output is one row per group, which is why in SELECT the grouping column is usually placed next to the aggregate.

What's checked

  1. one category|amount line per category

What it looks like