Subject Re: Aggregation and selectable SP
Author Svein Erling Tysvær
It should group on the combination, if you want to group on WEEK_NO
only, you have to remove SELLING_DATE from the equation, i.e.

select WOY.WEEK_NO WEEK, sum(S.TOTAL_DAY_SELLING)
from SELLINGS S
left join WEEK_OF_YEAR(S.TOTAL_DAY_SELLING) WOY ON 1=1
group by 1

Of course, you could add SELLING_DATE as a aggregate function if you
wanted, e.g. MIN(S.SELLING_DATE).

Set

--- In firebird-support@yahoogroups.com, "Carlos Macao" wrote:
> --- In firebird-support@yahoogroups.com, Svein Erling Tysvær wrote:
> Thank you for your reply,
>
> Nope, it still performs the aggregation over the S.SELLING_DATE
> instead WEEK_NO.
>
> Carlos Macao
>
> >
> > I think this should be something like
> >
> > select WOY.WEEK_NO WEEK, S.SELLING_DATE, sum(S.TOTAL_DAY_SELLING)
> > from SELLINGS S
> > left join WEEK_OF_YEAR(S.TOTAL_DAY_SELLING) WOY ON 1=1
> > group by 1, 2
> >
> > Though I must admit I've never tried it and don't know whether it
> > works or not...
> >
> > Set
> >
> > --- In firebird-support@yahoogroups.com, "Carlos Macao" wrote:
> > >
> > > Hi,
> > >
> > > I Want to obtain the selling total amount grouped by week
> > > number, how can I do this sum on a selectable SP?
> > >
> > > With this example, the aggregation is performed on the
> > > TOTAL_DAY_SELLING instead of the WEEK_NO.
> > >
> > > And I would prefer to this with a SP, rather than a UDF, for
> > > speed and installation reasons.
> > >
> > > select
> > > (select WEEK_NO from WEEK_OF_YEAR(S.TOTAL_DAY_SELLING)) WEEK,
> > > S.SELLING_DATE,
> > > sum(S.TOTAL_DAY_SELLING)
> > > from SELLINGS S
> > > group by 1, 2
> > >
> > > Thanks,
> > > Carlos Macao