I am newbie to sql, and this is my first time posting question here.
I created a table with 4 column. Item (which is Item no.) Description (the menu name) unit_price (price) and Qty (which is the order that has been made for that day). I want the qty of every item so i write this query:
select distinct(Item),description,unit_price,qty
from cdsitem
order by item
but the problem is it doesn't add all the qty in the specific item, it looks like this.
I want my output to become like this. the sum of quantity in every item no. and description
I hope someone can help me. Thanks
CodePudding user response:
You want an aggregation query:
SELECT item, description, unit_price, SUM(qty) AS qty
FROM cdsitem
GROUP BY 1, 2, 3;
Or use the more verbose version:
SELECT item, description, unit_price, SUM(qty) AS qty
FROM cdsitem
GROUP BY item, description, unit_price;
CodePudding user response:
select item,description,unit_price,sum(qty) as total_qty from cdsitem group by item;