Subject Re: [firebird-support] Doubt Regarding Sum() Function
Author PenWin
> SQL: Select BM.Book_Name, Sum(Book_Price) As 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

Someone has already told you that you should either add Book_Price to
GROUP BY (usually a better solution) or use MAX(Book_Price). Is there
any reason why you persist in using SUM which is completely unsuitable
for the task you want?

> I thought that "Book_Price" column value will be displayed as it is
> available in the "Book_Master" table and the records will be
> displayed only for those books which are having entries in
> "Book_Details" too.
> But it is comming as Book_Price * No. of records exist in
> Book_Detauils table.

Well, DUH! You are telling SQL to sum all Book_Price's for a particular
book. Since your recordset after joingin and before group operations
looks something like this:

ABC 1250.00 123
ABC 1250.00 456

Obviously the final displayed price will be Book_Price * Number of rows
for this book in Book_Details.

> If I would like to use the Sum() function for Book_Price too then how

First answer this: WHY do you want to use sum? Either you want a price
per book and then SUM is clearly unsuitable, or you want a total
earnings from books and then you should use SUM(Book_Price*Copy_Sold).