Is there a way to query like this in Oracle 9i?

Hi!
Before starting, some constraints: I can't use store procedures for this task, and should use ANSI99 wherever possible.
Let's suppose a table like this:
CREATE TABLE ELEMENTS
(REG_NAME VARCHAR2(10) NOT NULL, --PK
ELM_ORDER NUMBER(3,0) NOT NULL, --PK
ELM_NAME VARCHAR2(10) NOT NULL,
ELM_SIZE NUMBER(3,0) NOT NULL
It's a table describing some structures (REG_NAME), which contains elements (ELM_NAME) with the order number in register (ELM_ORDER) and its size (ELM_SIZE)
Some sample data '; ' separated fields, columns at first line:
REG_NAME; ELM_ORDER; ELM_NAME; ELM_SIZE
TYPE1; 1; VERSION; 3
TYPE1; 2; CALLNBR; 6
TYPE1; 3; DATE; 8
TYPE1; 4; EVENTTYPE; 4
TYPE1; 5; EVENTDESCR; 100
TYPE1; 6; EVENTCODE; 2
TYPE1; 7; ATTNAME; 10
TYPE2; 1; VERSION; 3
TYPE2; 2; CALLNBR; 6
TYPE2; 3; DATE; 8
TYPE2; 4; SOLCODE; 2
TYPE2; 5; SOLDESCR; 100
TYPE2; 6; ATTNAME; 10
I'd like to query the DB such way I could obtain:
VERSION 3 1 4
CALLNBR 6 4 10
DATE 8 11 19
EVENTTYPE 4 20 24
EVENTDESCR 100 25 125
EVENTCODE 2 126 127
ATTNAME 10 128 138
I.e, I need to obtain for an specific REG_NAME (TYPE1 in the sample query result), the columns ELM_NAME, ELM_SIZE of all rows in ELEMENTS table ordered by ELM_ORDER and the sum of ELM_SIZE of the previous rows + 1 and the same sum added by ELM_SIZE of the current row.
I'm almost sure there's a way to do that but I couldn't figure out how.
TIA,
WB::

If I understand your logic correctly, there are some calculation error in your sample result.
Don't know if this is possible using ANSI99, but in Oracle it is easy to do this:
SQL> CREATE TABLE ELEMENTS
  2  (REG_NAME VARCHAR2(10) NOT NULL, --PK
  3  ELM_ORDER NUMBER(3,0) NOT NULL, --PK
  4  ELM_NAME VARCHAR2(10) NOT NULL,
  5  ELM_SIZE NUMBER(3,0) NOT NULL
  6  );
Tabel is aangemaakt.
SQL> insert into elements values ('TYPE1',1,'VERSION',3);
1 rij is aangemaakt.
SQL> insert into elements values ('TYPE1',2,'CALLNBR',6);
1 rij is aangemaakt.
SQL> insert into elements values ('TYPE1',3,'DATE',8);
1 rij is aangemaakt.
SQL> insert into elements values ('TYPE1',4,'EVENTTYPE',4);
1 rij is aangemaakt.
SQL> insert into elements values ('TYPE1',5,'EVENTDESCR',100);
1 rij is aangemaakt.
SQL> insert into elements values ('TYPE1',6,'EVENTCODE',2);
1 rij is aangemaakt.
SQL> insert into elements values ('TYPE1',7,'ATTNAME',10);
1 rij is aangemaakt.
SQL> select elm_name
  2       , elm_size
  3       , sum(elm_size) over (partition by reg_name order by elm_order) - elm_size + 1 elm_size_2
  4       , sum(elm_size) over (partition by reg_name order by elm_order) + 1 elm_size_3
  5    from elements
  6   order by elm_order
  7  /
ELM_NAME                                 ELM_SIZE                             ELM_SIZE_2                     ELM_SIZE_3
VERSION                                         3                                      1                              4
CALLNBR                                         6                                      4                             10
DATE                                            8                                     10                             18
EVENTTYPE                                       4                                     18                             22
EVENTDESCR                                    100                                     22                            122
EVENTCODE                                       2                                    122                            124
ATTNAME                                        10                                    124                            134
7 rijen zijn geselecteerd.Regards,
Rob.

Similar Messages

  • Is there any way we can simplify this update query ?

    is there any way we can simplify this update query ? There is nothing wrong with the query ,but it looks so clumsy ...is there any other ways of doing this update  like using with clause  or exists or any other?
    [code]
    UPDATE STG_TMP_MBS_POOL s             SET s.instrument_id =             case  when  (                                     (select distinct iai.alternate_id  from                             instrument_alternate_id iai, STG_TMP_MBS_POOL s       where s.fi_instrument_id=iai.fi_instrument_id                             and  iai.alternate_id_type_code  IN (       'FMR_CUSIP','CUSIP'))  > 1)       then                             (select distinct iai.alternate_id from                             instrument_alternate_id iai, STG_TMP_MBS_POOL s       where s.fi_instrument_id=iai.fi_instrument_id                             and  iai.alternate_id_type_code =  'FMR_CUSIP')             else (select distinct iai.alternate_id from                             instrument_alternate_id iai, STG_TMP_MBS_POOL s       where s.fi_instrument_id=iai.fi_instrument_id                             and  iai.alternate_id_type_code IN ('FMR_CUSIP',       'CUSIP'))       END;
    [\code]

    update stg_tmp_mbs_pool s
       set s.instrument_id = case when (select distinct iai.alternate_id
                                          from instrument_alternate_id iai,
                                               stg_tmp_mbs_pool s
                                         where s.fi_instrument_id = iai.fi_instrument_id
                                           and iai.alternate_id_type_code in ('FMR_CUSIP','CUSIP')
                                       ) > 1
                                  then (select distinct iai.alternate_id
                                          from instrument_alternate_id iai,
                                               stg_tmp_mbs_pool s
                                         where s.fi_instrument_id = iai.fi_instrument_id
                                           and iai.alternate_id_type_code = 'FMR_CUSIP'
                                  else (select distinct iai.alternate_id
                                          from instrument_alternate_id iai,
                                               stg_tmp_mbs_pool s
                                         where s.fi_instrument_id = iai.fi_instrument_id
                                           and iai.alternate_id_type_code in ('FMR_CUSIP','CUSIP')
                             end
    Maybe
    begin
    update stg_tmp_mbs_pool s
       set s.instrument_id = (select distinct iai.alternate_id
                                from instrument_alternate_id iai,
                                     stg_tmp_mbs_pool s
                               where s.fi_instrument_id = iai.fi_instrument_id
                                 and iai.alternate_id_type_code in ('FMR_CUSIP','CUSIP')
    update stg_tmp_mbs_pool s
       set s.instrument_id = (select distinct iai.alternate_id
                                from instrument_alternate_id iai,
                                     stg_tmp_mbs_pool s
                               where s.fi_instrument_id = iai.fi_instrument_id
                                 and iai.alternate_id_type_code = 'FMR_CUSIP'
    where s.instrument_id > 1;
    end;
    Regards
    Etbin

  • I've copied my itunes library onto an external hard drive.  Is there any way I can do this and delete songs from my PC without also deleting from the external drive? Already lost two songs!!!

    I've copied my itunes library onto an external hard drive.  Is there any way I can do this and delete songs from my PC without also deleting from the external drive? Already lost two songs!!!  I just want a back up - using a work PC and don't want others accessing my songs.  Hope someone can help.  Thanks!

    I see. To get a better idea of what is being stored where please download and run the script iTunesInfo which should output something like this:
    I'm interested in the block of 4 results starting ITL location. If your profile name shows up somewhere replace it with <Name>.  It is also worth checking under Edit > Preferences > Advanced to see where iTunes thinks your media is supposed to go. My script estimates the setting based on the location of the first media file it can actually find.
    tt2

  • My first gen. iPad exits out of apps and safari at random times when I am trying to use them. So I basically can't do anything on it. Is there some way I can fix this?

    Crashing apps. What do I do to fix it?
    My first gen. iPad exits out of apps and safari at random times when I am trying to use them. So I basically can't do anything on it. Is there some way I can fix this?

    I have the same problem.  Yahoo Sportacular aborts every time I try to open it.  It attempts to load and then the device goes right back to the home screen.  The problem started April 26 after I switched leagues from NHL to NBA. Closing all apps and Restarting doesn't solve solve the problem.
    All other apps on the iPad work fine.  IPad2, OS6.
    Any other suggestions?  I suppose I could delete the app from the iPad and try re-installing it

  • I am a innkeeper at a bed and breakfast. we use a third party web reservation site. is there any way i can link this website to my calendar to where all web bookings will be uploaded to my calendar. i have the most recent software on my mac

    I am a innkeeper at a bed and breakfast. we use a third party web reservation site. is there any way i can link this website to my calendar to where all web bookings will be uploaded to my calendar. i have the most recent software on my mac

    Hi,
    Does the website have a WebDAV feed of their calendar?
    John M

  • Hi ive upgraded my itouch to ios 6.1.3 but it keeps crashing ounce i put my passcode in is there a way i can fix this? one of my  friends mentioed downgrading it but the only way isnt supported by apple so i dont feel safe with it so plzz help me

    hi ive upgraded my itouch to ios 6.1.3 but it keeps crashing ounce i put my passcode in is there a way i can fix this? one of my  friends mentioed downgrading it but the only way isnt supported by apple so i dont feel safe with it so plzz help me.
    it has worked fine no problems till i updated it i tried restoring itwith my old backup but it doesnt move the ios back so it just keeps on craching when i try to unlock it

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Restore from backup. See:                                 
    iOS: How to back up           
    - Restore to factory settings/new iOS device.
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar          
    Downgrading the iOS is not supported by Apple

  • HT2534 When I try to set up an Apple ID, it's asking for a credit card, and there is no "None" option, like this page suggests. How can I bypass this? This iPad is for a younger child who has no credit card, and will not need to make any purchases.

    When I try to set up an Apple ID, it's asking for a credit card, and there is no "None" option, like this page suggests. How can I bypass this? This iPad is for a younger child who has no credit card, and will not need to make any purchases.

    You can create an iTune and App Store account without credit card details
    1. Sign out of current Apple ID if you are sign-in to one (important)
    2. Go to App Store and select a free app
    3. Tap INSTALL APP
    4. Create New Apple ID
    5. Confirm Your Country
    6. Agree with Terms and Conditions
    7. Fill in your Apple ID and Password (you must create a new Apple ID; don't use your old Apple ID)
    8. Create and answer your secret question
    9. Select NONE for Payment Method
    10. Fill in Billing Address
    11. Submit application for new Apple ID
    12. Wait for verification email
    13. When email arrive, verify your account
    14. Start downloading your free apps

  • I upgraded to an iPad2 and recently pulled out my old iPad 1to re-gift to a family member. I can't remember the password I originally set up - is there a way to get beyond this?

    I upgraded to an iPad2 and recently pulled out my old iPad 1 to re-gift to a family member. I can't remember the password I originally set up - is there a way to get beyond this?  Each time I try a different password (trying any that I thought I might have originally used) it times out the tablet for up to an hour before I can try again.  Help?

    You can restore the device. That is what you have to do if you forget the passcode. You don't have to worry about syncing to your own computer either since you don't want to restore your data - you want to wipe it clean. Read these articles for more instructions
    iPad disabled -Wrong Passcode
    http://support.apple.com/kb/ht1212
    Updating or Restoring
    http://support.apple.com/kb/HT1414
    Sometimes you may not be able to bypass the passcode at all when you try to restore. You may need to restore by putting the iPad into recovery mode. I have heard from some users that they did not have to do this when they restore after forgetting the passcode - but just in case you need the information, this will help you with that procedure.
    Unable to Update or Restore
    http://support.apple.com/kb/ht1808

  • HT1212 my phone screen is broken and I bought a new phone but I want to get everything off my old phone. It will not sync to i tunes because it has a passlock on it. Is there any way to get passed this?

    My iphone screen and lock button are broken, I bought a new phone and want to get all the information off my old phone. My old phone will not sync with itunes because it has a pass code on it. I have no way to enter the pass code. Is there any way to get around this so I can still retrieve my information from it?

    If you are using the computer that you normally sync with, it should sync without entering the passcode. However, if this is not the computer you normally sync with, you cannot get past the passcode, it has to be entered.

  • I just planned to install windows 7 on my MBP Mid-2012 using VMware Fusion,so i am bit panic about viruses and malware's affecting through vmware,is there any way to avoid from this??

    i just planned to install windows 7 on my MBP Mid-2012 using VMware Fusion,so i am bit panic about viruses and malware's affecting through vmware,is there any way to avoid from this??

    usamasheikh wrote:
    virus protection in vmware or on my running OS X 10.8.2??plz help me out
    First, you can install Microsoft's Security Essentials in the Win 7 VM and keep it up-to-date. Second, you can turn off Sharing in Fusion's System Settings to keep the VM environment separate from your Mac. Third, you can look into Sophos Anti-Virus http://www.sophos.com/en-us/products/free-tools/sophos-antivirus-for-mac-home-ed ition/download.aspx for the Mac host.

  • Our Windows PC crashed with all our music on it.  There are copies of both purchased (thru iTunes store) and from our own CDs on another HD in a backup file.  They are not linked to a Media file.  Is there any way I can put this music on my new computer?

    Our Windows PC crashed with all our music on it.  There are copies of both purchased (thru iTunes store) and from our own CDs on an external HD in a backup file.  They are not linked to a Media file.  Is there any way I can put this music on my new computer?

    The syncing of music is one way, computer to phone. See this helpful document from a fellow user. Credit goes to the author.
    https://discussions.apple.com/docs/DOC-3141

  • My iPhone says that my charger is not supported, but it's the charger that came with my phone. Is there any way I can solve this issue?

    My iPhone says that my charger is not supported, but it's the charger that came with my phone. Is there any way I can solve this issue?

    Try cleaning out the phone's port, of pocket fluff and such. Carefully. And check the mains adapter similarly, but less likely.

  • My cellcom line doesn't work with my iPhone here in Israel, why? Is there any way I can solve this issue?

    My cellcom line doesn't work with my iPhone here in Israel, why? Is there any way I can solve this issue?

    Please explain.
    What does "cellcom line doesn't work with my iPhone" mean?
    What are you trying?  What is happening?
    Where did you buy the iphone?
    Any info abnout your issue at all?

  • I have a macbook pro with osx 10.8.2 and have the latest version of itunes. Whilst on itunes I realised that there was a shared library with musc on it. Is there a way I can download this music?

    Please help!

    You are seeing someone else's shared iTunes Library.
    Is there a way I can download this music?
    No, not without enabling Home Sharing, which would require using the same Apple ID and the other account holder's consent.

  • Whenever I try to sync my iPod Touch 5th gen with iTunes I get an error message saying "The iPod "*****" could not be synced because the sync session failed to start". Is there any way I can fix this?

    Whenever I try to sync my iPod Touch 5th gen with iTunes I get an error message saying "The iPod "*****" could not be synced because the sync session failed to start". Is there any way I can fix this?

    B-rock, thanks for posting the above.  I actually have the same issue, running Windows XP and I don't have that backup location, \Application Data\Apple Computer\MobileSync\Backup\.  When I go to Documents and Settings\(username)\ there's a AppData folder followed by:\LocalLow\DataMngr\ .
    I have the latest update, 5.0.1 and I have the iPod Touch 3rd gen.
    I have tried removing itunes and all that is associated with it then reinstalling and keep getting the same message.  I've reset my ipod thinking that would help but still, no backup.
    In iTunes, Edit, Preference, Device there are no backups.
    What am I doing wrong, can you help? 
    Thank you!

Maybe you are looking for

  • MobileMe gallery is still publishing to my iPhone - how to I stop it, please??

    I was having a tidy-up of my iPhone today and realised I have several albums in 'Photos' which derive from an old MobileMe account I had which published photos to my iPhone.  Aperture is not publishing to MobileMe, so I can't stop it from there.  You

  • Flash drive help??

    Hi, I have had my macbook pro for about a month, and I am a little clueless on some things..I have a flash drive, and how can I take my files (songs, pictures, etc) off to get saved on my mac? It is coming from a pc..

  • Which speakers are best?

    I've got an Audigy 2 ZS Notebook for my Dell XPS M70. Assuming money is of no concern, is there a certain speaker system that would be most suited for my setup?

  • Number of ipods to an account!!!

    I know probably everyone but me knows this answer. I heard that you can only have 3 ipods to a computer. I wanted to know if this is true. I also want to know how to share music. My oldest son got the first ipod, then me and we want to take some of h

  • Does Dreamweaver CS3  support implicit ftp over TLS?

    Does Dreamweaver CS3  support implicit ftp over TLS? I cannot find this option.