Rolliing backword window. How to calculate and get op like this

I have date as below
with abc as (select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 216 ilo_id, to_date('06/01/2009', 'dd/mm/yyyy') i_date from dual union all
             select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 215 ilo_id, to_date('05/01/2009', 'dd/mm/yyyy') i_date from dual union all
             select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 214 ilo_id, to_date('04/01/2009', 'dd/mm/yyyy') i_date from dual union all
             select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 213 ilo_id, to_date('04/01/2009', 'dd/mm/yyyy') i_date from dual union all
             select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 212 ilo_id, to_date('03/01/2009', 'dd/mm/yyyy') i_date from dual union all
             select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 211 ilo_id, to_date('02/01/2009', 'dd/mm/yyyy') i_date from dual)
select *
from   abc
USERID     CLO_ID      C_DATE                       ILO_ID  I_DATE           
         1         11 05/01/2009 00:00:00        216 06/01/2009 00:00:00
         1         11 05/01/2009 00:00:00        215 05/01/2009 00:00:00
         1         11 05/01/2009 00:00:00        214 04/01/2009 00:00:00
         1         11 05/01/2009 00:00:00        213 04/01/2009 00:00:00
         1         11 05/01/2009 00:00:00        212 03/01/2009 00:00:00
         1         11 05/01/2009 00:00:00        211 02/01/2009 00:00:00
Now i want to calculate rolling backword frequency of each ilo id and output should come like as based Frequency winodw
e.g. if frequency window is 2 then
USERID   CLO_ID C_DATE                     ILO_ID  I_DATE                        FREQUENCY
         1         11 05/01/2009 00:00:00        216 06/01/2009 00:00:00          2
         1         11 05/01/2009 00:00:00        215 05/01/2009 00:00:00          3
         1         11 05/01/2009 00:00:00        214 04/01/2009 00:00:00          3
         1         11 05/01/2009 00:00:00        213 04/01/2009 00:00:00          2
         1         11 05/01/2009 00:00:00        212 03/01/2009 00:00:00          2
         1         11 05/01/2009 00:00:00        211 02/01/2009 00:00:00          1
1. For each ILO ID, go back number od days given as Frequency window (in our case its 2)
2. calculate the number of ilo_id in that range
3. number of ilo_id is the frequency of that ilo_idHow can i achieve this.
Edited by: Kuldeep2 on Sep 29, 2010 2:30 AM
Edited by: Kuldeep2 on Sep 29, 2010 2:33 AM

Use analytic COUNT:
variable frequency number
exec :frequency := 2;
with abc as (select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 216 ilo_id, to_date('06/01/2009', 'dd/mm/yyyy') i_date from dual union all
select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 215 ilo_id, to_date('05/01/2009', 'dd/mm/yyyy') i_date from dual union all
select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 214 ilo_id, to_date('04/01/2009', 'dd/mm/yyyy') i_date from dual union all
select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 213 ilo_id, to_date('04/01/2009', 'dd/mm/yyyy') i_date from dual union all
select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 212 ilo_id, to_date('03/01/2009', 'dd/mm/yyyy') i_date from dual union all
select 1 userid, 11 clo_id, to_date('05/01/2009', 'dd/mm/yyyy') c_date, 211 ilo_id, to_date('02/01/2009', 'dd/mm/yyyy') i_date from dual)
select  abc.*,
        count(ilo_id) over(order by i_date range between :frequency - 1 preceding and current row) cnt
  from  abc
  order by i_date desc
    USERID     CLO_ID C_DATE        ILO_ID I_DATE           CNT
         1         11 05-JAN-09        216 06-JAN-09          2
         1         11 05-JAN-09        215 05-JAN-09          3
         1         11 05-JAN-09        214 04-JAN-09          3
         1         11 05-JAN-09        213 04-JAN-09          3
         1         11 05-JAN-09        212 03-JAN-09          2
         1         11 05-JAN-09        211 02-JAN-09          1
6 rows selected.
SQL> SY.

Similar Messages

  • How to calculate #Buffer Gets    # Exec           Buffer Gets/Exec

    Hi,
    How to calculate #Buffer Gets,# Execution time,Buffer Gets/Exec for a sql query?

    Nirmal
    You can find out these statistics from two places
    1) using SQL_TRACE (10046 trace) and then TKPROF (or Autotrace in SQL*Plus)
    2) or looking at V$SQL which records the cost assigned to each SQL statement since the statement was first cached.
    If you use Statspack or AWR, you can see the difference between two points in time, so you can calculate the cost for a period of time.
    See Using SQL_Trace and TKPROF
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96533/sqltrace.htm#1018
    and Using Statspack
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96533/statspac.htm#34837
    (see the 10g documentation equivalents if necessary).
    Remember, ratios (eg gets/exec) aren't always very helpful. You're best off concentrating on those operations which take longest (ie where there is the most potential to save time). See (eg) www.hotsos.com, www.oraperf.com, and others to identify effective performance methodologies.
    HTH
    Regards Nigel

  • When trying to install adobe photoshop cs4 on my new computer with windows 7 home premium and get a message to contact adobe because of an error. any ideas

    when trying to install adobe photoshop cs4 on my new computer with windows 7 home premium and get a message to contact adobe because of an error. any ideas

    JJMack <[email protected]> wrote:
    =============
    JJMack  created the discussion
    "when trying to install adobe photoshop cs4 on my new computer with windows 7 home premium and get a message to contact adobe because of an error. any ideas"
    To view the discussion, visit: https://forums.adobe.com/message/7092876#7092876

  • ICal Server email invitations - how to test and get this feature working

    iCal Server email invitations - how to test and get this feature working
    Thanks Apple for introducing this nice little feature into iCal but then completely neglecting to write any sort of useful manual that can explain what to do when it doesn't work after you set it up for the first time.
    At long, long last we have finally got there after about 6 months of fiddling on and off, so I thought I had better post up the process since many have similar issues and it is hard to ascertain what is going on.
    Using an external email server was just a waste of time and it still wouldn't handle the replies properly even though it was supposed to handle '+addressing'. In the end I set up a special gmail account for the iCal server and finally got it working. I list here the process of configuring and testing the system to check that each little stage is working.
    Set up a Gmail account in Apple Mail to access and test in the usual way for any email account (e.g. [email protected].);
    Set the iCal server email to access the same email using the following settings:
    IMAP
    SMTP
    [email protected]
    smtp.gmail.com
    Port: 993 [x] Use SSL
    Port: 587 [x] Use SSL
    User & Pwd
    Login
    User & Pwd
    To test the settings:
    send out a test email from Apple Mail to a non-server email address that you can access to check it has been received;
    send out a test email from your non-server email account to [email protected] and check that it is received;
    this tells you that the GMail account is setup correctly and working
    Testing iCal:
    I noted that iCal was deleting any emails that arrive in the inBox in Apple Mail as soon as they arrived (this is to be expected);
    test that the invites are being sent from iCal by setting an event in iCal and inviting your non-server address (you may not see any sign of this in Apple Mail but you should catch it in the iCal server log and possibly in the Gmail sent mail box);
    check that the invite is received at your non-server account and Accept it in iCal on another machine - the reply is automatically sent back;
    the replies appear in Apple Mail but are quickly deleted by iCal. But their record for you to see is left in Gmail under 'All Mail';
    Accepted invites appear as a notification button on the top left hand bar on iCal where you click to acknowledge them and then the attendee is shown as a green circled tick instead of a grey circled ?.
    this shows that iCal invitations are working correctly. Whenever an event is updated, all invitees should be updated by email automatically.
    I hope this helps anyone - I could certainly have done with something similar when I started with looking at this.
    Anatole
    The Error and Access logfile in the Server app under iCal server are very useful in determining any errors. I got lots of imip errors when I didn't quite have the settings right. The port is critical and it won't tell you this is the problem if it fails.

    iCal Server email invitations - how to test and get this feature working
    Thanks Apple for introducing this nice little feature into iCal but then completely neglecting to write any sort of useful manual that can explain what to do when it doesn't work after you set it up for the first time.
    At long, long last we have finally got there after about 6 months of fiddling on and off, so I thought I had better post up the process since many have similar issues and it is hard to ascertain what is going on.
    Using an external email server was just a waste of time and it still wouldn't handle the replies properly even though it was supposed to handle '+addressing'. In the end I set up a special gmail account for the iCal server and finally got it working. I list here the process of configuring and testing the system to check that each little stage is working.
    Set up a Gmail account in Apple Mail to access and test in the usual way for any email account (e.g. [email protected].);
    Set the iCal server email to access the same email using the following settings:
    IMAP
    SMTP
    [email protected]
    smtp.gmail.com
    Port: 993 [x] Use SSL
    Port: 587 [x] Use SSL
    User & Pwd
    Login
    User & Pwd
    To test the settings:
    send out a test email from Apple Mail to a non-server email address that you can access to check it has been received;
    send out a test email from your non-server email account to [email protected] and check that it is received;
    this tells you that the GMail account is setup correctly and working
    Testing iCal:
    I noted that iCal was deleting any emails that arrive in the inBox in Apple Mail as soon as they arrived (this is to be expected);
    test that the invites are being sent from iCal by setting an event in iCal and inviting your non-server address (you may not see any sign of this in Apple Mail but you should catch it in the iCal server log and possibly in the Gmail sent mail box);
    check that the invite is received at your non-server account and Accept it in iCal on another machine - the reply is automatically sent back;
    the replies appear in Apple Mail but are quickly deleted by iCal. But their record for you to see is left in Gmail under 'All Mail';
    Accepted invites appear as a notification button on the top left hand bar on iCal where you click to acknowledge them and then the attendee is shown as a green circled tick instead of a grey circled ?.
    this shows that iCal invitations are working correctly. Whenever an event is updated, all invitees should be updated by email automatically.
    I hope this helps anyone - I could certainly have done with something similar when I started with looking at this.
    Anatole
    The Error and Access logfile in the Server app under iCal server are very useful in determining any errors. I got lots of imip errors when I didn't quite have the settings right. The port is critical and it won't tell you this is the problem if it fails.

  • Anyone help? I click on buttons within websites and my mac opens new webpages advertising, mac keeper pro or some foreign exchange trading platform. Did i pick something hop in a download? how do i search for and get rid of this annoying infiltration?

    Anyone help? I click on buttons within websites and my mac opens new webpages advertising, mac keeper pro or some foreign exchange trading platform. Did i pick something hop in a download? how do i search for and get rid of this annoying infiltration?

    You've installed some form of adware. Take a look here:  http://www.thesafemac.com/arg/

  • Save password? how the **** can I get rod of this function!!! every time I sign to a place if I wanted to safe a bloody password I would do that!!!

    save password? how the **** can I get rod of this function!!! every time I sign to a place if I wanted to safe a bloody password I would do that!!!

    It is the same in the latest version 7.0.2. You can shut off the saving and auto filling of passwords by clicking in the menu bar at the top Safari > Preferences and then select Autofill and uncheck the passwords box. Also check the next pane as well.

  • I am planning to buy apple air mac book. i am not that technical will i be able to handle apple mac book. i am aware of using windows os but can i get software like that of notepad, word pad in os X lion. can i get partitioning in macbook,

    I am planning to buy apple air mac book. i am not that technical will i be able to handle apple mac book. i am aware of using windows os but can i get software like that of notepad, word pad in os X lion. can i get partitioning in macbook,

    Yes.  Switching to Mac might be overwhelming at first, but it is not difficult.  I Just started using Macs regularly about 9 months ago after using only Windows based pc's for over 15 years.  Macs come with TextEdit , but you can also purchase MS Office for Mac or use Apple's version, called iWork.Yes, you can partition the hard drive of a Mac.  Read these also: http://www.apple.com/support/switch101/, http://www.apple.com/support/mac101/.  With regular use of a Mac, you will be able to use it without even thinking about it, just like how you learned to use a WIndows pc.

  • HT4236 (PC) When I sync a folder of photos, they sync to the generic photo library on my iPhone, but it creates another folder with duplicates of the pictures. How do I prevent/get rid of this second folder?

    (PC) When I sync a folder of photos, they sync to the generic photo library on my iPhone, but it creates another folder with duplicates of the pictures. How do I prevent/get rid of this second folder?

    Um... that does not contain "duplicates".
    It's just a view that shows you everything that's in your other albums and events in one place...

  • Every time I send a file to the TRASH, finder ask me to type my system password to complete the removal and wasn't like this before. How do I make to work like it was before? Thanks.

    Every time I send a file to the TRASH, finder ask me to type my system password to complete the removal and wasn't like this before. How do I make to work like it was before? Thanks.

    http://www.thexlab.com/faqs/trash.html

  • How do I create an image like this?

    Completely new to PS. How would I create an image like this with text? https://www.facebook.com/photo.php?fbid=10151570901245020&set=pb.50687255019.-2207520000.1 366989903.&type=3&theater
    A link to a tutorial would be helpful.
    Thanks!

    Hi there,
    Are you referring to the text, the color effect, or both?
    Adding type is very easy - just grab the Type Tool from the tool bar. The article linked above provides some great tips for editing type in Photoshop.
    As is the case with many "how to's" for Photoshop, there are several ways to acheive the colorized effect like the one applied to image you linked to. One method is to use Adjustment Layers, which I have outlined below.
    1. With your image layer active (it will be highlighted in blue in your Layers panel, as shown below), create a selection of the area you'd like to colorize. I'm using the Polygonal Lasso Tool to create a diagonal selection - to do so, I held down the Shift key on my keyboard as a created my diagonal lines. This might take a bit of practice, but you'll get the hang of it quickly.
    2. Then, in your Adjustments panel (if you don't see it, go to Window > Adjustments), click on the Curves adjustment layer, as highlighted below. Now you can play around with the curves to get the effect you'd like. (Here's a quick guide on using the Curve tool)
    3. To select the other areas of your image, command (Mac) / control (PC) click on the adjustment layer thumbnail (highlighted below). Then, go to Select > Inverse.
    4. Now we want to deselect part of our selection. Grab the Quick Selection Tool from the toolbar and set it to Subract from selection. Then, simply drag the selection brush over the area you want to deselect. In my case, I only want to have the upper-left corner of my image selected.
    5. After you have your selection, click on the image layer and add a Curves adjustment layer like before.
    6. Repeat steps 3-5 for the other corner of your image and you should end up with something like this:
    The nice thing about using adjustment layers is that you can always change them - just double click on the Adjustment layer thumbnail (highlighted in step 3).
    Alternatively, you can select areas of your image and fill the selections with flat colors on separate layers. You can then go in a change the Blend Mode and Opacity for each layer.
    Feel free to reply with any questions!
    Kendall

  • Help - How do I create a template like this?

    Hi there,
    Can anyone tell me how to create a template website like this
    where the text and images are placed into odd shapes as opposed to
    boring 'awl AP DIVS.
    Many thanks for any help!
    Here's the website I'm talking about:
    www.agaveny.com

    thanks a mill but can you expand on that? how do I go about
    recreating a template like that? how can you have different lengths
    and widths for each rectangle? I don't get it - HELP!

  • My iPhone says Searching in the top right hand side and has been like this for 2 days. Already had a replacement sim yesterday, still not working. Apple advised me to restore my phone by connecting to iTunes. When trying to do this it's not allowing

    My iPhone says Searching in the top right hand side and has been like this for 2 days. Already had a replacement sim yesterday, still not working. Apple advised me to restore my phone by connecting to iTunes. When trying to do this it's not allow

    Are you on a Windows PC? Do you have anti-virus software running on it? Here are some help articles for you to troubleshoot with:
    Resolve iOS update and restore errors
    Resolve iOS update and restore errors in iTunes

  • How do i edit a picture like this

    Hey i was wondering how do i edit a picture like this? With the effect or whatever its called

    Image like that can be achieved many different ways there is no right or wrong no one way to do things in Photoshop.  There are also many third Add-Ons developed for Photoshop. Prices range from free to very expensive.  Several third party add on have been developed to process images and help produce image like your example.

  • I tried updating my ipod touch to iOS6 then an unknown error occured so i disconnected it an now it is stuck on the apple sign and has a loading sign and has been like this for 2 hours. what can i do?

    I tried updating my ipod touch to iOS6 then an unknown error occured so i disconnected it an now it is stuck on the apple sign and has a loading sign and has been like this for 2 hours. what can i do?
    My home button is also unresponsive and i have to press it really hard to make it work.

    Do you remember the the exact wording of the error message:
    Try:
    - iOS: Not responding or does not turn on
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iPod fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - If still not successful that indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.

  • How can I design hand logo like this?

    I want to explain how to design a hand logo like this, thank you very much.

    Have a look at this http://www.youtube.com/watch?v=-Uxl9-ktPN8 to get you started.
    For this kind of design (which CAN be designed in Photoshop) you might be better exploring Illustrator.
    Good Luck
    Cheers
    John

Maybe you are looking for