Subject Re: [ib-support] Re: Group by problem...
Author Daniel Rail
Hi,

At May 26, 2003, 17:43, johanfredse wrote:

> The table SG_CURRENT holds a record created every 15 minute. Every
> 24 hour it should be summed together into SG_HISTORY. The problem
> with grouping on all the fields is that the SG_CURRENT.ALARM_GRP
> field might have changed in mean time but should be ignored. The
> field is needed when presenting the summed data (selecting color
> codes).

Unfortunately, what Svend wrote is correct. And, that is the SQL
standard as well. If using aggregated fields, then all non-aggregated
fields have to be included in the GROUP BY clause. Otherwise, the
resulting data can be unpredictable.

> Therefore I need the grouping to work on the SG_CURRENT.OBJ_DATA
> field. Makes it easier without the DISTINCT or not?

The DISTINCT is not required, since the GROUP BY will take care of
this for you.

> If I skip the ALARM_GRP field it's OK but then I need to find
> another solution to add that later on...

Have you considered creating a stored procedure?


--
Best regards,
Daniel Rail
Senior System Engineer
ACCRA Group Inc. (www.accra.ca)
ACCRA Med Software Inc. (www.filopto.com)