 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kim G. Pedersen Guest
|
Posted: Sun Aug 31, 2003 1:33 am Post subject: Help with a Sql |
|
|
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
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 , please help
Running a old Mysql ,,, if it can be done without UNION and subselect I
would be nice .
Regards
Kim Pedersen
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|