Results 1 to 4 of 4

Thread: Lag function

  1. #1
    Join Date
    Nov 2005
    Posts
    4

    Unanswered: 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).

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    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'.

  3. #3
    Join Date
    Nov 2005
    Posts
    4
    Thanx for your anwer???

    Come on, is this helping out?

  4. #4
    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')

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •