Subject | Re: [ib-support] Re: Newbie question IB about select |
---|---|
Author | Martijn Tonies |
Post date | 2002-08-29T14:31:24Z |
Hi Woody,
It's not me who made the SQL rules, you know :)
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."
> > > > Anyway, when one uses an aggregate, all columns should beaggregated.
> > > >there
> > > > So, when using a SUM, MAX or GROUP BY etc you need to use
> > > > some kind of aggregate function on all resulting columns.
> > >
> > > Martijn,
> > >
> > > What do you mean by this? Are you saying that you shouldn't have any
> > > non-aggregate columns returned in an aggregate query? That's certainly
> > what
> > > it sounds like to me, or I am I just mis-interpreting what you mean?
> >
> > As soon as you use one aggregate function on a resulting column, you
> > need to use some sort of aggregate on the other columns too.
> >
>
> What purpose would it serve? Wouldn't that negate the possibility of using
> the group by for totaling certain groups of data together? For instance,
> assuming I have a table of data containing types of steel material and
> are different sizes weights and costs, how would you go about producing aWhat are you getting at? All of your resulting columns are aggregated ...
> query that groups the material by type and size with totals for weight and
> cost?
>
> Here is a sample breakdown of a simple table of materials:
>
> Table metadata: (Materials)
> MaterialType VarChar(15) // examples (410, 410S, 4130)
> MaterialSize1 Numeric(10,2) // size is of the form nn X nn so it
> MaterialSize2 Numeric(10,2) // is stored by each dimension
> MaterialWgt Integer // weight is strictly integer (540
> lbs)
> MaterialCost Numeric(10,2) // cost is per lb cost
>
> Assuming you wanted to produce a report that listed each type of material
> and break it down by each size, you want to show the total weight within
> each group and the total cost. Without combining aggregrate and
> non-aggregate columns, how would you do this?
>
> My query would look like this:
>
> 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)
It's not me who made the SQL rules, you know :)
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."