Renumber as groups?

Hello.

I need to copy the data to a temporary table in a target table. The data are the result of a selection process. There are clues, get gaps due to the selection.

When you copy, I need to reorganize the index if numbers the order of the entries is preserved, but the index numbers are consecutive again.
That's what I have:
    SQL>WITH my_data AS
       (    SELECT 1 AS id1
                 ,     CEIL(  400
                            - DBMS_RANDOM.VALUE( 1
                                               , 30
                                                ) )
                     * 10
                   + LEVEL
                     AS id2
                 , LEVEL * 2 AS index_nr
              FROM DUAL
        CONNECT BY LEVEL < 7
        UNION ALL
            SELECT 2 AS id1
                 ,     CEIL(  200
                            - DBMS_RANDOM.VALUE( 1
                                               , 30
                                                ) )
                     * 10
                   + LEVEL
                     AS id2
                 , LEVEL * 3 AS index_nr
              FROM DUAL
        CONNECT BY LEVEL < 9
        UNION ALL
            SELECT 3 AS id1
                 ,     CEIL(  300
                            - DBMS_RANDOM.VALUE( 1
                                               , 30
                                                ) )
                     * 10
                   + LEVEL
                     AS id2
                 , LEVEL * 3 AS index_nr
              FROM DUAL
        CONNECT BY LEVEL < 5)
SELECT renumberd.*
     , ROWNUM AS new_index_nr
  FROM (  SELECT *
            FROM my_data
        ORDER BY id1
               , index_nr) renumberd
     
       ID1        ID2   INDEX_NR NEW_INDEX_NR
---------- ---------- ---------- ------------
         1       3731          2            1
         1       3762          4            2
         1       3913          6            3
         1       3914          8            4
         1       3805         10            5
         1       3876         12            6
         2       1731          3            7
         2       1882          6            8
         2       1813          9            9
         2       1964         12           10
         2       1715         15           11
         2       1956         18           12
         2       1737         21           13
         2       1808         24           14
         3       2721          3           15
         3       2792          6           16
         3       2953          9           17
         3       2854         12           18
and that's what I need:
.      ID1        ID2   INDEX_NR NEW_INDEX_NR
---------- ---------- ---------- ------------
         1       3731          2            1
         1       3762          4            2
         1       3913          6            3
         1       3914          8            4
         1       3805         10            5
         1       3876         12            6
         2       1731          3            1
         2       1882          6            2
         2       1813          9            3
         2       1964         12            4
         2       1715         15            5
         2       1956         18            6
         2       1737         21            7
         2       1808         24            8
         3       2721          3            1
         3       2792          6            2
         3       2953          9            3
         3       2854         12            4
Think of id2 < tt > < /tt > as being random.
Id1 < tt > < /tt > order is not important so much as the order of id2 < tt > < /tt > s (determined by the original < tt > index_nr < /tt > s) within id1 < tt > < /tt > Group is preserved.

Is this possible with a single statement?

Good bye
DPT

Published by: DPT Opitz Consulting com on 07.05.2013 11:55
select
id1,id2,index_nr
,row_number() over (partition by id1 order by index_nr)
 new_index_nr
from my_data

ID1     ID2     INDEX_NR     NEW_INDEX_NR
"1"     "3801"     "2"     "1"
"1"     "3992"     "4"     "2"
"1"     "3863"     "6"     "3"
"1"     "3944"     "8"     "4"
"1"     "3985"     "10"     "5"
"1"     "3846"     "12"     "6"
"2"     "1741"     "3"     "1"
"2"     "1962"     "6"     "2"
"2"     "1753"     "9"     "3"
"2"     "1724"     "12"     "4"
"2"     "1735"     "15"     "5"
"2"     "1716"     "18"     "6"
"2"     "1857"     "21"     "7"
"2"     "1788"     "24"     "8"
"3"     "2811"     "3"     "1"
"3"     "2952"     "6"     "2"
"3"     "2933"     "9"     "3"
"3"     "2774"     "12"     "4"

Tags: Database

Similar Questions

  • Renumbering of a group of .jpg files.

    I have a group of photos I want to renumber not start at 100 1. For example, I wish they were on day 1 (100) .jpg, Day1 .jpg (101). I work under Windows Vista and cannot get to renumber the day 1 (1) for everything.

    Is there a way to do this?

    I have a group of photos I want to renumber not start at 100 1. For example, I wish they were on day 1 (100) .jpg, Day1 .jpg (101). I work under Windows Vista and cannot get to renumber the day 1 (1) for everything.

    Is there a way to do this?

    ===================================
    The following procedure should work.

    Right-click in the first picture in a select group of photos
    and choose Rename.

    Enter first name:

    Day 1 (100) .jpg

    Press enter

    The following names should be:

    Day 1 (101) .jpg

    Day 1 (102) .jpg

    Day 1 (103) .jpg

    Volunteer - MS - MVP - Digital Media Experience J - Notice_This is not tech support_I'm volunteer - Solutions that work for me may not work for you - * proceed at your own risk *.

  • I want to group my pictures in a folder

    Hello

    I want to group my photos in a folder using whatever program photo came on my windows vista computer, so I've grouped the first group with Disneyland1, 2 Disneyland, etc.

    The second group's adventure 1, 2, so on.  And then another group

    1 water park, water park 2, etc.

    and a final category last day 1, day 2, etc.

    Unfortunately this is not group by alphabetical order.  When the folder opens up, last few days ago then some disneys, then it adventure, then waterpark and then back to disney and last day.

    How can I put the subgroups in a layout I want, where they are all together so I can easily choose the photos I want to use to make a photo book?

    I tried to go to the windows live photo gallery, but they are always blurred and I cannot yet understand how to drag the photos to where I want to that they.

    Is there an easy way to drag the photos I want to order?  It is not letting me do them so I have to do the part in my other windows program supplied with the computer.

    Please email me so I know your answer.  I haven't used this help online before, so I don't know how it works.

    Thank you

    Sorry... I don't know how you renamed the files but
    the method I've tried to explain the works for me you can
    See in the screenshots.

    If you renumbered files correctly... closing and re-
    opening of the file may have been the fix.

    Apart from that I can only guess you number don't did not
    the second group in the same way again...
    with (10001).

    Leave a space after the first letter, use parentheses.
    start the sequence with a number number (not only
    zeros),

    A file .jpg (space) Group Name (space) (10001)

    Before posting this reply I tried again... Here is the
    screenshot.

    Summer, fall, winter, spring
    http://images2.Snapfish.com/232323232%7Ffp5398%3A%3Enu%3D95%3A4%3E%3B78%3E259%3EWSNRCG%3D33%3C%3A85673734%3Anu0mrj

  • When I send a mass text by enabling / disabling message group, then I turn on message group, suddenly became a group text responses?

    When I send a mass text by enabling / disabling message group, then I turn on message group, suddenly became a group text responses?

    I sometimes send jokes or notifications to multiple contacts.  After I mass text them by activating / deactivating iMessage and Group Messages, then I switch on iMessage and Group Messages - will people I sent a mass text message can see phone numbers and the responses of the other?

    I think it should not because after sending the text it comes just up on their phone as a text message you only, but I want to just make sure

    Thank you

    Hello Eddie7777,

    Thanks for your post. I understand that you wanted to confirm if a mass message will convert to a group message after activating again Group Messaging. I certainly understand wanting to send a mass text message without launching a group of crazy message where number of all is shared. I'll be more than happy to help clarify.

    I tested on my iPhone, and so my previous knowledge on the messages, I discovered some great information. When you send a mass text with disabled group messaging message, it sends the messages individually and these other people only get a text without your mass SMS numbers. When you have enabled messaging group once again, it won't change the message on their end, and if they say it will for you.

    Hope this helps explain things!

    Take care!

  • Show all members of the Group of developer tools?

    How can I view all of the current members of the developer tools group?

    Hello Michael,

    Unfortunately, it is quite difficult. Here are some solutions:

    http://superuser.com/questions/279891/list-all-members-of-a-group-Mac-OS-x

    https://jamfnation.jamfsoftware.com/discussion.html?ID=15503

  • How can I create a group through Outlook without the application Outlook email?

    How can I create a group by using Outlook without an application Outlook email?

    Sigmalambda wrote:

    How can I create a group by using Outlook without an application Outlook email?

    It is difficult to understand what you're trying to do. You can create a group and send an email to the group in any mail client. The recipients can use any e-mail provider or an e-mail client to receive e-mail. Please explain in more detail what you are trying to accomplish.

  • iMessages group Conversation does not go in DND

    I've just updated to iOS 10 on my iPhone more than 6 and a group conversation in the Messages that I sometimes put on DND now does not recognize that the conversation has been implemented within DND.  Messages continues to inform me about all messages from anyone in the group.  Is there any solution for this?

    Thank you

    Brent

    Have what troubleshooting you tried? Troubleshooting user steps include reboot, reset, restore from backup, restore to factory; tests after each stage.

    If you return in the message after the ignition of the DND, does always show as it is turned on?

  • I restored my iPhone 6 from an itunes backup, but my group chat contacts are changed

    So I backed up my iphone on itunes because I went to the apple store to solve a problem I had. After that that they had deleted everything on my phone, I went home and tried to restore it. All went well, all my contacts were saved, my pictures, etc. so I waited so he could complete the synchronization for my laptop. While I was checking my messages, I noticed that many of the cats from group I had, had shared some of my names of friends with other people on my contact list. I also saw that other people who were in the GM had their photo ID, but instead of their name, their phone numbers were posted. I rebooted my phone and hope so that it can be corrected, but it didn't, I also tried to add the people who did not appear in the newsgroup, but I have added to them, the person that they have been replaced by a show! If anyone can help me on how to solve this problem, it would be highly appreciated!

    Hello, arsmars!

    Thank you for using communities of Apple Support. Looks like your Contacts are not being very cooperative since you have restored your iPhone iOS 10 6. I know that I have not memorized a phone number in ages and would need this support as soon as possible. I'll be happy to help you.

    It seems that you use iCloud to synchronize contacts between devices. On your iPhone, go to settings > iCloud. Disable the Contacts, wait 5 seconds, then turn it back on and check your Messages and Contacts.  I have a link below if you are still having problems:

    Get help using iCloud Contacts, calendars, or reminders

    I wish you a great weekend!

  • IOS 10 Notifications: Please bring back ability to group by app notifications

    Please, please, please bring back the ability to group by app notifications...

    And why Apple consider it an improvement "," to take away our ability to choose how we sort our notifications in the first place? Not happy at all to this subject :-(. Some of us are _a_lot_ notifications, and also be able to group by app notifications means that we can then _clear_ notifications by app, as well (i.e. clear specific _types_ of the notifications at a time), which is VERY useful... With respect, this is a gross oversight on the part of Apple. I'm an ardent loyal fan, very long Apple products, but 'small', absurd decisions like this add up, making it more difficult and more difficult to justify is not something else.

    -Thank you!

    Apple is not read here.

    Submit your Apple asking this feature here:

    http://www.Apple.com/feedback

  • iOS 10 - auto bluetooth with contact group synchronization

    I have my iPhone 5s coupled to my car bluetooth hands-free system.

    With iOS 9 I was able to sync only certain groups of Contacts from iPhone. It was helpful that I have a number of groups in iPhone Contacts, including one specially created for syncing to my car.

    Since the update of my iPhone to iOS 10, I have that option in the bluetooth settings of the iPhone to check any combination of 'Favorite phone', "Phone Recents" or "All Contacts". None of them are useful for me as I want to synchronize with one of the original groups in Contacts.

    Help, please!

    Thank you.

    The same problem. A month ago I could synchronize specific groups with the phone book from my car. Now, the only option is "Contact".  Help!

  • add/delete a contact group message iOS 10

    Can't seem to find how to delete/add contact group message since the update to iOS on iPhone 10 6. Solutions?

    nessrez wrote:

    Can't seem to find how to delete/add contact group message since the update to iOS on iPhone 10 6. Solutions?

    Send a message from your iPhone, iPad or iPod touch - Apple Support Group

    This is possible with an imessage group all users using an Apple device.

    You can't do it for a group message MMS - mix Apple and not Apple device device.

  • iOS 10 - how to group by app notifications?

    I just downloaded and installed the new 10 iOS and the first thing I noticed that I want to change is the notifications. I would like to bring grouped by app once again, how I put them up on iOS 9. However, I can't find this option anywhere in the settings. Can someone please tell me how I can change this setting, or if it is no longer an option?

    Thank you in advance.

    You are right. The new Notification Center so difficult of our lives and our long

    Please Apple return the old function "sort by apps.

  • If I go buy Apple Watch nike, that I can use other groups like leather band?

    If I go buy Apple Watch nike, that I can use other groups like leather band?

    At this point, all we know is here:

    https://www.Apple.com/Apple-watch-Nike/

  • I do my job to the computer on a MAC computer. I want to create a document using Pages and then convert the document to PDF and send a group email. I want to send the PDF using the pdf for each receiver icon must click the icon to open t

    I do my job to the computer on a MAC book PRO. I want to create a document using Pages and then convert the document to PDF and send a group email. I want to send the PDF using the pdf for each receiver icon must click the icon to open the document. My problem is the document does not show the icon, but rather the document is already open. I spoke with 2 Apple. 'Experts' care and can help me. Can someone tell me what to do?

    It's a question of how the recipients e-mail programs deal with attachments. Many e-mail programs will open all the files they can handle, including files jpg and PDF, by default, and if the recipient has not changed that there is nothing you can do about it. The only solution is to the compress first, then it will be delivered as an attachment, allowing the recipient to decompress and open it.

  • I can't see Group Conversations?

    My phone number has recently added 2 cats of Imessages group. For one of them, I personally entered the phone number. However, on my Iphone I can't see group conversations. I can't see any discussion group click on everything. I have group messages and MMS on. Also, I tried to reset the network settings, restart my Iphone and turn on/off Imessages. I currently have 9 Ios. Everyone in the group the cats have been the reception and sending of the messages that I don't know. Is there a solution?

    This article can help:

    Send a message from your iPhone, iPad or iPod touch - Apple Support Group

    To quote a few excerpts: If you send a message to group of people who don't use an iMessage, the message is sent as an MMS or SMS message.  Messages MMS & SMS groups appear in green text bubbles and go through your carrier instead of Apple. In addition, when you send an SMS to group, all responses are sent as individual text messages and recipients cannot see the other answers in the group.

    So, if you are having problems with Group SMS and MMS messages, I think you will need to contact your support provider.

Maybe you are looking for