I imagine that you are looking for something like this:
SELECT
name,
producent,
model,
number,
SUM(quantity),
warehouse,
location
FROM store
WHERE
quantity > 0
GROUP BY
name,
producent,
model,
number,
warehouse,
location
ORDER BY
number;
I removed id
from the selected fields, since you are already declaring that as a UNIQUE
(PRIMARY KEY
) field in the CREATE TABLE
statement earlier (becauase it is autoincremented by the sequence you are declaring). You never want to group on a UNIQUE
field - it will just give you the same results as without it.
But in order to be certain, we need to know what you want your output to look like.
A rule of thumb here, when it comes to grouping results with SQL is this: Always include all the fields that are selected outside of an aggregate function in the GROUP BY
clause.
Update
You have edited your question, so that the original query you included is gone. But it looks like you have included the results that you want instead. Here's how you would get those:
SELECT
name,
number,
SUM(quantity) as "quantity"
FROM store
WHERE
quantity > 0
GROUP BY
name,
number
ORDER BY
number;
I hope you can accept the answer like this.