Aggregate function, Grouping



When I try to execute the sql statement:

SELECT
bl.GR_KEY, bl.GroupOrder, bl.UseOverhead,
SUM (Amount * price) as "SubTotal",
IIF (bl.UseClientAmount = True,
bl.Amount + bl.ClientAmount,
bl.Amount) as "RealAmount"
FROM
Budget_Lines bl
GROUP BY
bl.BU_KEY, bl.GroupOrder, bl.UseOverhead, bl.GR_KEY
HAVING
bl.BU_KEY = :BU_KEY

I get an exception, because the Group By fields do not match the Select fields.

But if I include the fields:

GROUP BY
bl.BU_KEY, bl.GroupOrder, bl.UseOverhead, bl.GR_KEY,
bl.UseClientAmount, bl.Amount, bl.ClientAmount

- the result is wrongly grouped. Can I avoid this problem?

Regards,
Kim
.



Relevant Pages

  • Re: Aggregate function, Grouping
    ... SUM (Amount * price) as "SubTotal", ... bl.Amount)) as "RealAmount" ...
    (borland.public.delphi.database.ado)
  • Re: how do I get the address of a cell to calculate with it
    ... Subtract the price for the start date from the price on the end date. ... Dim StillLeft As Double ... Dim AmountThisSlice As Double ... StillLeft = Amount ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Rounding of amounts
    ... Please keep all correspondence within the NewsGroup, ... What would you want to do with an amount of 2.899999 ... the selling price in ounces, ... which calculates the rounded selling price in ounces. ...
    (microsoft.public.excel)
  • Re: VIRGIN on the ridiculous
    ... X amount of people who leave. ... Virgin work heavily on a marketing approach, i think there sales teams are ... in which the price doublkes at the end of the promotion, ... you want to be a virgin customer you need to be "ACTIVE" customer chasing ...
    (uk.telecom)
  • Help with a queries
    ... price as money,' obviously the price of a traded item ... volRemaining as int ' amount of the item availabe on stock, ... can be from the same City or Country. ...
    (microsoft.public.sqlserver.programming)