Subject Re: [firebird-support] group by week
Author Helen Borrie
At 02:00 AM 18/10/2003 -0400, you wrote:
>james_027 wrote:
>
> > doesn't anybody here an an idea how to do the group by week select
> > sql?
> >
> > thanks
>
>I think I heard somewhere that FB now lets you group by udf functions?
>Is this correct anyone?

Yes, since Fb 1.0, in fact.

>If not, I usually make a view using FreeUDFLib
>and its functions like F_DAYOFWEEK and then create a query based on that
>view that groups by the return value of that function.
>
>Always been kind of a pain to do that way...but...

To group by week, you would need f_WeekOfYear - as long as you don't care
what day of the week each "week" begins. I don't know what day of the week
this function uses at all. Monday = first day of the business week?

You can do this in a direct query or a view - all same-different. ;-)

select f_WeekOfYear(cast(sales_date as DATE)),
product_code,
sum(item_cost)
from sales_detail
where sales_date between '26.12.2002 00:00:00' and '25.12.2003 00:00:00'
group by 1, 2 /* for fb 1.5 */
{group by f_WeekOfYear(cast(sales_date as DATE), product_code for fb 1.0}

h.