Subject Re: Group by problem...
Author johanfredse
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).

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

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

Maybe thats the easiest way?

Cheers
/johan

--- In ib-support@yahoogroups.com, "Svend Meyland Nicolaisen"
<news@s...> wrote:
> All fields which isn't selected using a aggregate function such as
AVG needs
> to be included in the GROUP BY clause, as you have done in the
second query
> example. What grouping do you expect?
>
> -
> SMN
>
>
> -----Original Message-----
> From: johanfredse [mailto:johanfredse@y...]
> Sent: 26. maj 2003 20:24
> To: ib-support@yahoogroups.com
> Subject: [ib-support] Group by problem...
>
>
> Hi!
>
> Why does the following GROUP BY give me an error? I'm using
Firebird
> RC1 on a XP.
>
> SELECT DISTINCT SG_CURRENT.BLD_CODE,
> SG_CURRENT.GRP_CODE,
> ...
> ...
> ...
> AVG( SG_CURRENT.S24 ) AS SUM24
> FROM SG_CURRENT
> GROUP BY SG_CURRENT.OBJ_CODE
> ORDER BY SG_CURRENT.GRP_CODE, SG_CURRENT.OBJ_CODE,
> SG_CURRENT.OBJ_TYPE
>
> but if i make it
> GROUP BY SG_CURRENT.BLD_CODE, SG_CURRENT.GRP_CODE,
> SG_CURRENT.OBJ_CODE, SG_CURRENT.OBJ_TYPE, SG_CURRENT.BOX,
> SG_CURRENT.MUX, SG_CURRENT.ALARM_GRP
> it will work but givs me wrong grouing!?
>
> Thanks for any help!
>
> Cheers
> /Johan
>