tags:

views:

95

answers:

3

Basically this code below returns the right information, but I need to add the quantities together to bring back one record. Is there any way of doing this?

select category.category_name, (equipment.total_stock-equipment.stock_out) AS Current_Stock, equipment.stock_out
from
EQUIPMENT,
CATEGORY
WHERE  EQUIPMENT.CATEGORY_ID = CATEGORY.CATEGORY_ID
and category.category_name = 'Power Tools'
+1  A: 

1 - Sum() and Group By will do the trick

2 - Post your questions only once, in one post, its easyer

DonOctavioDelFlores
+1  A: 

Sounds like a SUM and GROUP BY to me, one record returned for eaach GROUP.

Why is one record important? Are you trying to combine querying and rendering in a single step? My advice: don't.

duffymo
+6  A: 

You want to use the SUM function and a GROUP BY clause.

select category.category_name, SUM((equipment.total_stock-equipment.stock_out)) AS Current_Stock, SUM(equipment.stock_out) as stock_out
from EQUIPMENT, CATEGORY 
WHERE EQUIPMENT.CATEGORY_ID = CATEGORY.CATEGORY_ID and category.category_name = 'Power Tools'
GROUP BY Category.Category_Name
Chris