BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with a Sql

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Kim G. Pedersen
Guest





PostPosted: Sun Aug 31, 2003 1:33 am    Post subject: Help with a Sql Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.