Subject Re: [firebird-support] Doubt Regarding Sum() Function
Author Vishal Tiwari
Hi Daniel,
 
I have already tried with that sql you have provided and no doubt it's working fine.
 
My doubt is that if there are multiple records in the both table and you need to get the sum of respective column's from respective tables, the if I use the Sum() function the sql I wrote would not work, but what is the best way to achieve this. This may seems easy, but how do I get the result using Sum().
 
Regards.
 
 
Vishal

--- On Tue, 14/9/10, Daniel Rail <daniel@...> wrote:


From: Daniel Rail <daniel@...>
Subject: Re: [firebird-support] Doubt Regarding Sum() Function
To: firebird-support@yahoogroups.com
Date: Tuesday, 14 September, 2010, 8:02 PM


 



Hi,

At September-14-10, 9:40 AM, Vishal Tiwari wrote:

> Hi,
>  
> Required result is as follows:
>  
> Book_Name   Book_Price   Copy_Sold
> ABC               1250.00          1130
> LMN               5698.00          240
> PQR               1524.00          1972
>  

Then your query should be:

Select
BM.Book_Name,
BM.Book_Price,
Sum(COPY_SOLD) As COPY_SOLD
from Book_Master BM
Join Book_Details BD On BM.Book_Name = BD.Book_Name
Where BD.YearMonth = '200904'
Group By BM.Book_Name, BM.Book_Price

Or, it can also be:

Select
BM.Book_Name,
BM.Book_Price,
(select Sum(BD.COPY_SOLD)
from Book_Details BD
where BM.Book_Name = BD.Book_Name
and BD.YearMonth = '200904') As COPY_SOLD
from Book_Master
order by BM.Book_Name

--
Best regards,
Daniel Rail
Senior Software Developer
ACCRA Solutions Inc. (www.accra.ca)
ACCRA Med Software Inc. (www.filopto.com)










[Non-text portions of this message have been removed]