SQLite GROUP BY clause

The GROUP BY clause is an optional clause that can be used with the SQLite SELECT statement. It is used for coding data queries.

When applying the GROUP BY statement data rows are returned for each group. This is helpful when combined with a aggregate function. Exemplary aggregate functions in SQLite are:

  • SQLite MIN
  • SQLite MAX
  • SQLite SUM
  • SQLite COUNT
  • SQLite AVG

Relevant syntax is demonstrated below:

SELECT 
  col_01,
  MIN(col_2)
FROM
  table
GROUP BY
  col_01, col_02;

Now an example:

SELECT
  client_id, COUNT(value)
FROM 
  sales
GROUP BY 
  client_id;
Close

Meta