Subject use of SUM
Author Sudheer Palaparambil
Hi,

How to SUM the line_discount on line no.2 ?

1. SELECT S.bill_no, S.discount, SUM( SD.line_value ),
2. SUM( ( SD.line_value * SD.discount_p ) / 100 ) AS line_discount
3. FROM sale S LEFT JOIN sale_det sd ON ( SD.company_id = S.company_id )
4. AND ( SD.parent_id = S.id )
5. WHERE ( ( S.company_id = :dCID ) AND ( S.entry_date = :dAsOn ) )

Is this the correct way to sum ? Or should I use SUM for individual column

like this ?

( SUM( SD.line_value ) * SUM( SD.discount_p ) ) / 100 AS line_discount

Since I am populating all numeric fields to non-null values, I am not
bothered about checking for NULL values here.

Thank you.

Sudheer Palaparambil