"Sum" according to products

"Sum" according to products

Post by YWxp » Tue, 30 Oct 2007 17:01:00


I have a table with two products (currently) "petrol" & "diesel"

------------------------------------------------------------------------------------
ID Product_iD Product Original_amt Draw Outstanding
1 101 Petrol 1200 100 0
2 102 Diesel 3000 50 0
3 101 Petrol 1200 150 0
4 101 Petrol 1200 200 0

------------------------------------------------------------------------------------

I bought $1200 of Petrol and $3000 for the Deisel.

As time goes, i draw them down for private use.

------------------------------------------------------------------------------------

My question:

I'd like to see the "sum of total draw-down" of each product.

------------------------------------------------------------------------------------


Therefore, my desired result should look like this:



product_id product Total_Draw_Down
101 Petrol 450
102 Diesel 50



------------------------------------------------------------------------------------

Thank you so much, experts ! ^_^!


--
Allen Phailat Wongakanit
 
 
 

"Sum" according to products

Post by QW5keSBIdW » Tue, 30 Oct 2007 20:26:04

Hi Allen

product_id product Total_Draw_Down

Try the following SQL...

select product_id, product, sum(draw_down) as total_draw_down
from TableName
group by product_id, product


hth

Andy Hull