Unix Technical Forum

Re: Range between a number of days

This is a discussion on Re: Range between a number of days within the DB2 forums, part of the Database Server Software category; --> "Gert van der Kooij" <gk-ibm-db2@xs4all.nl> wrote in message news:MPG.196400ca76e09c8989885@news.xs4all.nl... [sni] > > > > without using the days() function ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008, 09:46 AM
Paul Vernon
 
Posts: n/a
Default Re: Range between a number of days

"Gert van der Kooij" <gk-ibm-db2@xs4all.nl> wrote in message
news:MPG.196400ca76e09c8989885@news.xs4all.nl...
[sni]
> >
> > without using the days() function
> >
> > SELECT MIN(due_date) OVER(ORDER BY days(DUE_DATE)
> > RANGE BETWEEN 60 PRECEDING AND CURRENT ROW )
> >
> > which works, but that query isn't satisifed by DB2 directly from the an

index
> > on DUE_DATE so I get a tablescan (of a sorted temp table).
> >
> > I guess I need a generated column days(DUE_DATE) that I can put in the
> > index...
> >

>
> If I understand the RANGE option right it doesn't restrict the rows
> returned so it seems normal to use a tablescan. Don't you need a where
> clause on this query?


The query has to process rows in DUE_DATE order, I've got an index on DUE_DATE
with the intent of avoiding the sort. If I have no where clause, I'll get an
index scan followed by table lookups which is what I want. The hassle is that
the days() function does not use the index.

I'm 99% sure that I can't x DAYS / x MONTHS / x YEARS ... in the RANGE clause,
and it's just a little bit of a shame considering that one big motivation for
the OLAP functions is the ability to calculate things such as 60-day moving
average...

Regards
Paul Vernon
Business Intelligence, IBM Global Services


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:15 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com