Is it possible to reset agg function row_number()

Hi
I am having a little trouble with aggregate functions.
In this scenario an item always has a slot for each period. Periods are sequential.
What I want is that if an item changes slot, the number of periods in slot resets to one even if it has been in that slot before and the start period in slot be the last time it moved into that slot rather than demonstrated below.
CREATE TABLE tmp_table (item VARCHAR2(10),period NUMBER,slot VARCHAR2(10));
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',1,'A');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',2,'A');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',3,'A');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',4,'B');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',5,'B');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',6,'C');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',7,'A');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',8,'A');
INSERT INTO tmp_table (item,period,slot) VALUES ('abc123',9,'C');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',1,'D');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',2,'D');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',3,'E');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',4,'E');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',5,'D');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',6,'D');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',7,'E');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',8,'E');
INSERT INTO tmp_table (item,period,slot) VALUES ('def456',9,'D');
SELECT
  item
, period
, slot
, FIRST_VALUE(period)
  OVER (PARTITION BY item, slot
        ORDER BY period) start_period_at_slot  
, ROW_NUMBER()
  OVER (PARTITION BY item, slot
        ORDER BY period) periods_in_slot
FROM tmp_table
ORDER BY item,periodgives me
ITEM           PERIOD SLOT       START_PERIOD_AT_SLOT PERIODS_IN_SLOT
abc123              1 A                             1               1
abc123              2 A                             1               2
abc123              3 A                             1               3
abc123              4 B                             4               1
abc123              5 B                             4               2
abc123              6 C                             6               1
abc123              7 A                             1               4
abc123              8 A                             1               5
abc123              9 C                             6               2
def456              1 D                             1               1
def456              2 D                             1               2
def456              3 E                             3               1
def456              4 E                             3               2
def456              5 D                             1               3
def456              6 D                             1               4
def456              7 E                             3               3
def456              8 E                             3               4
def456              9 D                             1               5
18 rows selected.Notice when the item abc123 moves back into slot A it picks up where it left off with periods in slot of 4 but I would like to find a way to manipulate this to reset to zero and the start period in the slot be 7 rather than 1.
and subsequent rows ordered on period to increment appropriately.
Any help much appreciated.
Thanks
Ian

You mean this?
SQL> select item
  2       , period
  3       , slot
  4       , row_number() over (partition by item, sumx order by period) rn_period_at_slot
  5    from ( select t.*
  6                , sum(x) over (partition by item order by period) sumx
  7             from ( select t.*
  8                         , case lag(slot) over (partition by item order by period)
  9                           when slot then 0
10                           else 1
11                           end x
12                      from tmp_table t
13                  ) t
14         )
15   order by item
16       , period
17  /
ITEM           PERIOD SLOT       RN_PERIOD_AT_SLOT
abc123              1 A                          1
abc123              2 A                          2
abc123              3 A                          3
abc123              4 B                          1
abc123              5 B                          2
abc123              6 C                          1
abc123              7 A                          1
abc123              8 A                          2
abc123              9 C                          1
def456              1 D                          1
def456              2 D                          2
def456              3 E                          1
def456              4 E                          2
def456              5 D                          1
def456              6 D                          2
def456              7 E                          1
def456              8 E                          2
def456              9 D                          1
18 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • Is it possible to reset password for any user using abap program

    Hi friends,
    Is it possible to reset password for any user using abap program by specifying client number and user id. in selection screen.
    if any code for that to reset password please mail me.
    Thanks & Regards,
    Yogesh

    Hello Yogesh,
    Yes you can reset the password for any body using ABAP Code. But for that you really don't need any client number.
    If this process is on regular basis, then recommended is to use BAPI for changing the user details Otherwise BDC also works fine.
    => Function Module - BAPI_USER_CHANGE
    Call this in the program for resetting the password.
    => CALL TRANSACTION 'SU01' USING InternalTable
    This will be executed in the BDC of SU01 transaction recording. Use the Password Change button in the application toolbar of transaction while recording.
    Hope this helps.
    PS If the answer solves your query, plz close the thread by marking it solved and rewarding each reply.
    Regards

  • Can´t sync movies with iTunes 11.1.4 (on Mavericks 10.9.1) to iPhone 4S with iOS7. Is there a possibility to reset the sync on iTunes?

    I produced some videos in iMovie 10.0.2 and transfered they to iTunes 11.1.4.
    That worked so far....
    After that I´ve compressed the movies for the use with iPhone and iPod
    .....also worked.....
    Then I tried to sync the movies to my iPhone4s with iOS7.0.4. The sync starts, runs and ends without an error. But after that I can´t find the movies on my phone. There is enough free memory on my phone and I also tried to shut the movie app and restart my phone. The movies are still not there.
    When I check what´s on my phone with iTunes (iPhone connected), iTunes says the movies are on my phone!?!?!?
    Maybe there are some troubles within a sync "library" or something like that? Is there a possibility to reset the sync services or whatever is responsible for the sync?
    Or maybe somebody has another solution which solves the problem!?
    The strange thing is that my music, books and all the other stuff will sync fine!
    Hope that someone can help me with this issue.
    thanks a lot

    I´ve fixed this issue as follows:
    1) did a backup of the iPhone in the cloud
    2) reset the iPhone in manufacturing mode
    3) restored the backup out of the cloud
    After that the sync with iTunes worked well also with movies.

  • My iphone does not have facetime on it.  I've tried going into restrictions, but there's a passcode that doesn't seem to be one that I've used before.  Is it possible to reset the phone and then just restore a portion of the old information?

    My iPhone does not have Facetime on it.  I've tried going into restrictions, but there's a passcode that doesn't seem to be one that I've used before.  Is it possible to reset the phone and then just restore a portion of the old information?  I've tried several pass codes and now am locked out for an hour after being locked out for 5 minutes and then 15 minutes.  It said that I had tried 7 pass codes prior to these, but I don't remember ever trying to get into restrictions before.
    I've looked up other posts on this, and my phone was purchased in the US and does not have an AE in the model number.

    Help for forgotten passcode >   iOS: Forgotten passcode or device disabled after entering wrong passcode
    When you have access to your iPhone again, FaceTime is a pre installed app that cannot be removed.
    Try a search >  iOS: Understanding Spotlight Search

  • Is it possible to define a function in the MathScript Node

    Is it possible to define a function in the MathScript Node

    You can not define a function inside of a MathScript Node, but only because it isn't necessary. The way custom functions work in MathScript is that they are saved in .m files located in paths in the MathScript path list. When the MathScript compiler receives a function that it doesn't recognize, then it searches for it in the path list, and upon finding it, compiles and loads the function. You can specify these search paths manually by going to File>>MathScript Preferences from the MathScript Window or dynamically by using the path() command within a script.
    To answer your original question, if you would like to create custom functions dynamically within a VI, then you can simply build your custom functions using strings and then save them to an ASCII file with the extension .m. You could either save the file to a path already in the MathScript path list or you could dynamically specify the path by passing the path into a MathScript Node as a string and by using the path() command at the beginning of your script to set it.
    Kind Regards,
    E. Sulzer
    Applications Engineer
    National Instruments

  • Possible to reset component metrics in OEM?

    Is it possible to reset the component metrics in OEM for a given composite app?
    I'd like to run a baseline performance test, reset the metrics, then do a revised run & profile the change.
    This is straightforward in OSB, but I haven't seen a way of doing it in OEM.
    thanks
    Garret

    Hi...
    If you are referring to a MobileMe account, try this support article  >  Mac OS X: Resetting the SyncServices folder
    If instead you are referring to restarting the AMDS, for Mac OS X v10.6.8 or earlier > iTunes: How to remove and reinstall the Apple Mobile Device Service on Mac OS X

  • IIs it possible to retrive deleted Function Module

    Hi all,
    i just want to know is it possible to retrive deleted Function Module .
      the request is not released yet.

    Hi Sai,
    Its not possible. (Confirm by contacting ur Basis people, if they can help).
    But the following is valid only if your function module is(or was) a transportable object.
    Go to SE37, enter your function module name and create. Assign it to the same function group and have the same interface and description. Save it, activate it.
    Now go back to SE37, enter the function module name, in the menu, 'Utilities>Versions>Version Management'. Now you should see all your previous versions. Select the most recent past version. Do a retrieve and then activate it as the latest version.
    Not sure if it works. But still give it a try.
    Best Regards,
    Anjali
    Message was edited by: Anjali Devi

  • How to ignore nulls in analytic functions ( row_number() and count())

    how to ignore nulls in analytic functions ( row_number() and count())

    Iam attaching test data can any one help me please
    thanks in advanceeeee
    CREATE TABLE TEMP_table
    ACCTNUM NUMBER,
    l_DATE TIMESTAMP(3),
    CODE VARCHAR2(35 BYTE),
    VENDOR VARCHAR2(35 BYTE)
    insert into temp_table values (1,sysdate+1/60,'bso','v1');
    insert into temp_table values (1,sysdate+2/60,'bsof','v1');
    insert into temp_table values (1,sysdate+3/60,'bsof','v2');
    insert into temp_table values (1,sysdate+4/60,'','v1');
    ian executing this my ;
    SELECT acctnum,l_date,vendor,code_1,
           CASE
             WHEN code = 'bsof'
              AND COUNT (DISTINCT code) OVER (PARTITION BY acctnum, vendor) > 1
              AND row_number () OVER (PARTITION BY acctnum, vendor ORDER BY vendor, l_date) != 1
             THEN 'yes'
           ELSE 'no' END result
      FROM  (select  acctnum,l_date,vendor, code code_1, case when code IN ('bso', 'bsof') then code
      else null end code   from  TEMP_TABLE
    ORDER BY acctnum ,l_date);
    my result :
    1    3/23/2011 5:24:34.000 PM    v1    bso    no
    1    3/23/2011 5:48:36.000 PM    v1    bsof    yes
    1    3/23/2011 6:36:41.000 PM    v1    bsof    yes
    1    3/24/2011 11:55:53.000 AM    v1        no
    1    3/23/2011 6:12:38.000 PM    v2    bsof    no
    I need to eliminate nulls  in top query not in inner query (not using where condition in inner query)
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Is is possible to call a function or method before JVM exits ??

    Hi All,
    Is is possible to call a function or method before JVM exits where System.exit() is used.
    I am calling a program where System.exit is used. i need to call a function before the JVM exits.
    Please help me.
    Thanks,
    J.Kathir

    How to call the method ? Did i have to call the shudown hooks method in my main class ?
    Is it possible to have in subclass?
    is the below code is correct ? i am calling a class before System.exit is called....
    java.lang.Runtime.getRuntime().addShutdownHook(...My Own Class()....)

  • I forgot my password for my mac book retina which I just bought 1 1/2 months ago. Is there any possibility to reset it?

    Hi, I forgot my password for my mac book retina which I just bought 1 1/2 months ago.
    Is there any possibility to reset it? I guess (not sure) the operating system is os x.

    Forgot Your Account Password
    For Snow Leopard and earlier
         Mac OS X 10.6- If you forget your administrator password
    For Lion/Mountain Lion
        Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
         When the menubar appears select Terminal from the Utilities menu.
         Enter resetpassword at the prompt and press RETURN. Follow
         instructions in the dialog window that will appear.
         Or see Reset a Mac OS X 10.7 Lion Password and
         OS X Lion- Apple ID can be used to reset your user account password.
    If you are unable to boot from an installer DVD:
    (these will only work on Leopard or earlier)
      1. Boot to Safe Mode by restarting and after the chime press and hold down
          the COMMAND-S keys until a black screen with white type appears.
      2. At the prompt, type the following commands pressing return after each
          command line:
         /sbin/fsck -yf
         If you do not receive a "Filesystem OK" message then repeat this command
         until you do.  If after seven tries you still do not receive a "Filesystem OK"
         message, then the system is corrupted and needs to be reinstalled.
         mount -uw /
         cd /private/var/db/netinfo
         mv local.nidb local.old
         rm ../.AppleSetupDone
         shutdown -r now
    The second-to-last command above will cause OS X to think that the operating system is newly installed, and when the new owner starts up the computer it will send him/her to the startup wizard where he/she can start a new user without reinstalling.
    This last method does not actually change a password. It simply removes the user accounts and lets you create an initial admin account as if the computer were new out of the box.
    Reset Admin Password Using The Terminal
    You can reset the password by printing out (or writing down) and carefully following these steps.
    First, find the short name of the admin user on the machine. The easiest way of doing this is by looking at what the directory is called in the Users folder.
    Now, start in Single-user Mode. It should boot into a command line.
    Enter these exact lines. Press RETURN after each.
    mount -uw /
    ifconfig lo0 up
    cd /var/db/netinfo
    netinfod -s local
    Now you'll need that short name. Enter "passwd", a space, and the short name of the admin. For example, if the admin was rather prosaically called "imadmin", you would enter "passwd imadmin".
    The computer will now prompt you to change the password for "lmadmin" (or whatever the short name was). Go ahead and enter a new password.
    Now, enter:
    sync
    reboot
    and the machine will reboot. The admin password should now be changed.

  • Is it possible to call Normal function Module from WD4A , Not RFCs

    Is it possible to call Normal function Module(FM) from WebDynPro for ABAP , Not RFCs

    There is no difference, unless you are specifically calling the RFC to connect to another system. If so, then you need to add the DESTINATION keyword to the function call and specify the destination name. This name must be defined in SM59.  But, if you are not going to another system, you can call the RFC the same way you call the regular function module.
    REgards,
    Rich Heilman

  • Is it possible to perform doDML functionality in ViewObject

    Hello,
    In Oracle Forms to ADF conversion, different forms is sharing same entity object. As a result,
    different pre-Insert, Pre-update, etc. is requied.
    Is is possible to perform doDML() functionality in ViewObject instead of the Entity Object?
    Thanks

    No, but what you could do is create a transient attribute in the EO, of which each VO sets a different value. Thus when the doDML method is called, it could check the value of the transient attribute, and execute different functionality based on the transient.
    CM.

  • Possible to reset the workspace to mimic the older, classic PS look?

    I really don't like the new workspace / palets layout in PS CC. Does anyone know if it's possible to reset the workspace / palets / interface look to mimic the older, classic PS look that we've all been using for so long?
    -John

    There's nothing radically different about Photoshop CC.
    Don't speak for others.  Many serious Photoshop users have upgraded through every version.  The changes have all been evolutionary.
    That said, for more specific help, maybe you could supply a little more info?  How about describing specifics, such as what you're seeing that's different, how you'd like it to look.
    For all you've written, it's possible that you may just want to disable the Application Frame in the Window menu.  We can't really tell.
    -Noel

  • Is it possible to refer label functions to a function contained in a class

    Is it possible to refer label functions to a function
    contained in a class. eg
    labelFunction = myClass.formatFunction
    This would save me repeating code.

    "nikos101" <[email protected]> wrote in
    message
    news:ghrj6p$m8l$[email protected]..
    > As my applications grow I'm finding it more and more
    appealing to starting
    > moving my common funcitons into classes, functions like
    this for example:
    >
    > private function dateFilterFunction(item:Object):Boolean
    > {
    > var t:Boolean = false;
    > if(item.valueDate.time >=slider.values[0] &&
    item.valueDate.time
    > <=slider.values[1]){
    > t = true;
    > }
    > return t;
    >
    > }
    >
    > Can Other developers share their experiances of doing
    things this way
    > please
    > ;-)
    I don't see where that makes sense as a class method. Could
    you provide
    more details about how you're using this?

  • It is not possible to reset to factory State

    Ciao
    My pc has this problem: "it is not possible to reset to factory State"
    Noteboock  HP Pavilion dv6-6c65el
    OS: Windows 7 Home Premium 64-bit SP1
    CPU Intel Core i5-2450M CPU @ 2.50\3.10GHz hd3000 integrata
    Graphics Radeon HD 7690M XT 2Gb GDDR5
    BIOS Brand Hewlett-Packard
    Version F.12 Date 10/26/2011
    Hard disk (C) OS+(D) Recovery+(E) HpTools. 
    After performing "reset factory state" (with HP Recovery Manager) I noticed the malfunction IE9 32bit.
    Moreover, the absence of other software preinstalled (missing: Hp Hp setup-documentation-IE9 64bit).
    When I tried a new reset, HP Recovery Manager to the voice system recovery (factory state) tells me:
    (disabled: to restore the system, use recovery media)
    Using Recovery DVD (in excellent condition),you  receive the following error message:
    "windows as encountered a problem comunicating with a device connected to your computer-This errorcan be cause by umpluggin a
    removable storage device such as an exsternal usb drive while the device is in use,or by faulty hardware such as hard drive or cd-rom drive
    that is failing make sure any removable storage is properly connected and then restart your pc" Status:0xc00000c9 Info: an unespected I\O error as occurred"
    The same happens with the F11 key during startup. Reset error.
    The System Restore Microsoft does not resolve.
    In Windows everything else seems to work and the hardware of the notebook has no problems.
    The original dvd player has been replaced with a compatible; reads all the disks supported.
    Only install MSE (I use only portable software).
    There are no viruses or other malaware.
    I performed procedures in hp support but nothing has changed.
    You can find a solution?
    Ciao e grazie
    Lecce2
    This question was solved.
    View Solution.

    I have no more 'answer because my computer had crashed complete.
    I apologize.
    Order the media why?
    If discs created the first time the PC will not work. I suppose that does not solve the problem discs hp (I also read about a problem like mine. This problem has not been resolved with the media bought by HP).
    I shot weeks the web and I finally found the appropriate procedure.
    I made several attempts to solve the problem. But now I have succeeded.
    1- Show Hidden Files \ protected
    2- Enter with a program (es: file commander) in recovery partition and copy the file or files base.wim. My is about 18 Gb, 1 file.
    3- We need a second PC and dvd
    4- Follow a procedure described by internauta 37.
    Search "Ripristinare portatile HP senza DVD e se l'HP Recovery Manager non funziona Internauta37"
    E 'was for me a little complicated but in the end I have my hp to the state of factory and everything works perfectly.
    Thank you all

Maybe you are looking for

  • How To Start a DATABASE created by DBCA?

    Hello Forum mates I Have created 1 database with DBCA as oracle user but when i try to startup it throws errors ORA-01078 and LRM-00109. i have created other databases manually they startup when i run .env file, where is the env file for dbca created

  • Pass word recovery

    I have just got myself this computer and set it up last night with pass words and all that . But for some unknowen reason it will not except my pass word to log on to the computer is there any way i can bypass this with out useing the pass word wizar

  • IPhone can't play songs and import songs from PC at my workplace. Why?

    Hi. I just bought an iPhone and i set up my iphone on itune at home and have also imported the songs from there into the iphone. But, when i connect my iphone to the itune at my workplace, i can't play the songs i already have in my iphone on itune o

  • X6 - new FMW 31.0.004

    I see that it is avaliable, but I can't find any change log, pretty wierd !?! Did anyone tested? Nokia why you didn't put some change log? I only found on one forum that one guy had some strange problems with a noisy in microphone after update, and t

  • E71 Nokia Maps testing mode

    Buying subject seller told me there are 7 days of trial use of Nokia Maps, after that I will have to purchase a licence code. But application doesnt allow me to navigate and from the beginning offers to purcgase an activation code. How can buy anythi