Hi

Having 2 tables

TOrders:

ProductID   Amount
4008                10
4008                 -5
4110                  7
4110                  2
4110                 -4
4110                  1

TStock
ProductID     Count
4110               3
4110               2

What I want Is a sum of product need to be produced.

I try without the stock first :-)

  Select O.ProductID , Sum(Amount) from TOrders O
  group by O.ProductID having sum(O.Amount)>0

work nice so I try include the stock:

  Select O.ProductID , Sum(Amount) from TOrders O
  left join Tstock S on S.ProductID=O.ProductID
  group by O.ProductID having sum(O.Amount)-Sum(S.Count)>0

result ->

ProductID    SUM(Amount)  Sum (count)
4008            5            0
4110        12 #6*2         20   #(2+3)*4      should have been 6 and 5


Hope u can see problem (some kind of "Cartesian product" ) , please help

using mySQL 4.014

Regards
Kim Pedersen
macaos/elprint Development


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to