Subject Re: [ib-support] Re: Newbie question IB about select
Author Martijn Tonies
Hi Woody,


> > > Select MaterialType, MaterialSize1, MaterialSize2, sum(MaterialWgt),
> > > sum(MaterialWgt * MaterialCost) from Materials
> > > Group by MaterialType, MaterialSize1, MaterialSize2
> > >
> > > In what way would you change the query not to use non-aggregate
columns?
> > > Woody (TMW)
> >
> > What are you getting at? All of your resulting columns are aggregated
...
>
> Is not the definition of an aggregate column one whose value is computed?
> The above doesn't compute the material type or size, only the combined
> weight and cost. In IB (and FB I believe) the SQL rules state that to use
> Group By in an aggregate query, you must include all non-aggregate
columns,
> right?

As soon as you use 1 aggregate, you need to use aggregates on all others.
GROUP BY is an aggregate, just like SUM, MAX etc...

So by specifying MaterialType and MaterialSize1 & 2 in the GROUP BY
clause, you're using an aggregate on all columns - so this should work...

>
> >
> > It's not me who made the SQL rules, you know :)
> >
>
> Sure, blame someone else... <VBG>

Where and whenever I can ... :)


With regards,

Martijn Tonies
InterBase Workbench - the developer tool for InterBase and Firebird
http://www.interbaseworkbench.com

Upscene Productions
http://www.upscene.com

"This is an object-oriented system.
If we change anything, the users object."