If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Lag function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-08-07, 14:33
zimon72 zimon72 is offline
Registered User
 
Join Date: Nov 2005
Posts: 4
Lag function

Ok, here's my problem:

I have made a table that contains for two years (24 months), for two product groups, the turnover per month (for each productgroup). I would like to use these turnovers to predict the future turnovers for both productgroups for the coming 12 months.

I am able to predict future turnovers for one productgroup, using the lag function. But how do I do that for two productgroups? Is that using the partition by clause, or by using the order by???

Please help. I am not at my work currently, tomorrow I can give my sql script (it's all in Oracle SQl, so no other options are available).
Reply With Quote
  #2 (permalink)  
Old 01-08-07, 17:00
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Once you got your database back, why wouldn't you try both PARTITION BY and ORDER BY and see which one will give the correct result? Or, even better, first read documentation about it so that you'd know what is 'partition by' used for, and what 'order by'.
Reply With Quote
  #3 (permalink)  
Old 01-09-07, 01:59
zimon72 zimon72 is offline
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanx for your anwer???

Come on, is this helping out?
Reply With Quote
  #4 (permalink)  
Old 01-09-07, 02:04
zimon72 zimon72 is offline
Registered User
 
Join Date: Nov 2005
Posts: 4
Ok, for people who are really into helping, here's my syntax:

select a.periode,b.clusters,b.roy_aantal_sec,
--
trunc(((0.4*lag(b.ROY_aantal_sec,1) over (partition by b.clusters order by a.periode,b.clusters)+0.6*lag(b.ROY_aantal_sec,2) over (partition by b.clusters order by a.periode,b.clusters))+
(0.05*lag(b.ROY_aantal_sec,12) over (partition by b.clusters order by a.periode,b.clusters)+0.95*lag(b.ROY_aantal_sec,24 ) over (partition by b.clusters order by a.periode,b.clusters)))/2) as voorspelling
--
from periode a
left outer join tst2 b
on (a.periode=b.periode and b.lob='IC')
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On