quick_learner42
quick_learner42

Reputation: 416

total unique items

I have an SQLite database and in it are stored, as an example:

COUNT  DESCRIPTION  SIZE
5      red boxes    5x5x20
3      blue boxes   8x8x8
3      red boxes    5x5x20
4      green panels 10x10
7      blue boxes   5x5x20

Is it possible to achieve a summary like:

8  red boxes    5x5x20
3  blue boxes   8x8x8
7  blue boxes   5x5x20
4  green panels 10x10

Upvotes: 0

Views: 25

Answers (1)

TheWolf
TheWolf

Reputation: 1385

SELECT SUM(count) AS count, description, size
FROM table
GROUP BY description, size
ORDER BY count

SUM is an aggregating function combining several rows into one. The GROUP BY clause lists all fields that have to be the same so that rows are allowed to be combined (in your example, only two rows are combined into one).

Upvotes: 1

Related Questions