How can I Update the table so that....

I have a table XYZ with values like
x y
1 null
1 null
1 null
1 null
2 null
2 null
3 null
4 null
4 null
4 null
I want to update my table so that the values for column y appears the serial no for the given x. The output would be like
x y
1 1
1 2
1 3
1 4
2 1
2 2
3 3
4 1
4 2
4 3
How can I write the Update statement?

SQL> CREATE TABLE t (x INTEGER, y INTEGER)
Table created.
SQL> INSERT INTO t
     VALUES (1, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (1, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (1, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (1, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (2, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (2, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (3, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (4, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (4, NULL)
1 row created.
SQL> INSERT INTO t
     VALUES (4, NULL)
1 row created.
SQL> UPDATE t t1
   SET y =
          (SELECT l
             FROM (SELECT ROWID rid,
                          ROW_NUMBER () OVER (PARTITION BY x ORDER BY NULL) l
                     FROM t t2)
            WHERE t1.ROWID = rid)
10 rows updated.
SQL> SELECT *
  FROM t
         X          Y
         1          1
         1          2
         1          3
         1          4
         2          1
         2          2
         3          1
         4          1
         4          2
         4          3
10 rows selected.

Similar Messages

  • How can I update the table with a single query for...

    I have a table with columns C1 and C2.
    C1 C2
    A1 null
    A1 null
    A1 null
    A1 null
    A2 null
    A2 null
    A2 null
    A3 null
    A4 null
    A4 null
    I want to update my table with a single query so that I would have data like
    C1 C2
    A1 1
    A1 2
    A1 3
    A1 4
    A2 1
    A2 2
    A2 3
    A3 1
    A4 1
    A4 2
    The updated column C2 has the values like serial no grouped on the column C1.

    SQL> create table mytable
      2  ( c1 varchar2(2)
      3  , c2 number(2)
      4  )
      5  /
    Tabel is aangemaakt.
    SQL> insert into mytable (c1)
      2  select 'A1' from dual union all
      3  select 'A1' from dual union all
      4  select 'A1' from dual union all
      5  select 'A1' from dual union all
      6  select 'A2' from dual union all
      7  select 'A2' from dual union all
      8  select 'A2' from dual union all
      9  select 'A3' from dual union all
    10  select 'A4' from dual union all
    11  select 'A4' from dual
    12  /
    10 rijen zijn aangemaakt.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1
    A1
    A1
    A1
    A2
    A2
    A2
    A3
    A4
    A4
    10 rijen zijn geselecteerd.
    SQL> merge into mytable t1
      2  using (select c1
      3              , row_number() over (partition by c1 order by null) rn
      4              , rowid rid
      5           from mytable
      6        ) t2
      7     on (t1.rowid = t2.rid)
      8   when matched then
      9        update set c2 = rn
    10   when not matched then
    11        insert values (null,null)
    12  /
    10 rijen zijn samengevoegd.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1                                      1
    A1                                      2
    A1                                      3
    A1                                      4
    A2                                      1
    A2                                      2
    A2                                      3
    A3                                      1
    A4                                      1
    A4                                      2
    10 rijen zijn geselecteerd.Regards,
    Rob.

  • My old email/Apple ID  is showing up connected to the iCloud backup but I have long since changed my Apple ID to my new email address.  How can I update the iCloud so that I can pull the backup down to my new iPAD?

    How do I redirect my iCloud to my new email address that has long since ALREADY been registered as my Apple ID

    Settings > iCloud > Delete Account and then log back in with the updated version of your account

  • HT4623 how can i update my iphone 4 that does not have the update option in the settings?

    How can i update my iphone 4 that does not have the update option in the settings?

    From the article you linked, scroll down to the section "Update your device using iTunes"

  • How can I update the "basic" Adobe Flash Player that is in my Samsung Smart TV?

    How can I update the "basic" Adobe Flash Player that is in my Samsung Smart TV?

    Any update would come from Samsung, but in low-margin products like TVs, it's pretty uncommon for OEMs to provide ongoing maintenance over a large span of years.  You may find that you'll get a better experience from a dedicated streaming box like ChromeCast/Roku/etc.

  • I have an iPad that I want to update to IOS 5.1. I have several apps that each were installed using a different iTunes ID. How can I update the IOS without losing the apps?

    I have an iPad that I want to update to IOS 5.1. I have several apps that each were installed using a different iTunes ID. How can I update the IOS without losing the apps?

    To update your phone requires using the latest version of iTunes, on your computer, as well as Internet access. The update to iOS 5.0 or higher is an erase/restore deal, so you not only have to make sure all of the content, currently on your phone, is on your computer and accessible, you need to update iTunes first, have Internet access, then update your phone. There is no way around this fact. You could go to an Apple store or use another computer, but you run the risk of losing all of your data it you do that.

  • How can i update the REMARK field in ADRT database table

    Hi all,
    How can i update the REMARK field in ADRT database table
    By using Function modules or BAPI’s
    Please reply me fast

    Hi,
    you can try this code:
        SELECT SINGLE * FROM KNA1 WHERE KUNNR = wa_kunnr.
        IF sy-subrc = 0.
          CLEAR adrct.
          SELECT SINGLE * FROM adrct WHERE addrnumber = kna1-adrnr.
          IF sy-subrc = 0.
            adrct-remark = wa_remark.
            MODIFY adrct.
          ENDIF.
        ENDIF
    best regards,
    Thangesh

  • How can I update the trigger table?

    I need a insert trigger on a table and also wants to insert the result value in one of its field.
    it gives mutating error........
    so wots the way of updating it? how can i update the same table.

    For example like this (inside the BEGIN/END section of the trigger):
    :NEW.Col2 := :NEW.Col1;
    C.

  • How can i update the ADRT table REMARK field

    How can i update the ADRT table REMARK field
    by using only function modules or BAPI's not by direct update's
    please help me
    i need it urgently

    Hi,
    you can try this code:
        SELECT SINGLE * FROM KNA1 WHERE KUNNR = wa_kunnr.
        IF sy-subrc = 0.
          CLEAR adrct.
          SELECT SINGLE * FROM adrct WHERE addrnumber = kna1-adrnr.
          IF sy-subrc = 0.
            adrct-remark = wa_remark.
            MODIFY adrct.
          ENDIF.
        ENDIF
    best regards,
    Thangesh

  • How can I update the project varibles  in OBPM 10.3

    Hi All,
    OBPM version : 10.3.2 (weblogic Enterprise version)
    How can I update the project variables from the External process?
    I per my knowledge we use termination wait activity and notify the same from the external process. I am successfully do this but I am facing the performance issue with this and sometimes even data sources pool is getting exhausted.
    Could you please tell me is there any other way to update the project variables?
    Thanks in advance.
    Narasimha
    Edited by: Narasimha on Mar 2, 2011 4:19 AM

    I do not disagree with Mark about using Message Waits to update project variables. I'm right in the middle of logic right now that is doing just that.
    If you have thousands (or in your case millions) of instances to update all at once, you might want to also want to consider another approach. I obviously do not know your process and sure you've thought of this, but you could use a database to store this same information that you are currently using project variables for. You'd need a table that has the instance's unique id (e.g. case id, loan number, claim number) as the primary key and then have columns to store the information you are currently storing in project variables.
    Taking this approach, you'd be updating the milliions of rows in the database very quickly. You could still have project variables in your process, but they would be set at the beginning of a Screenflow or in an Automatic activity using a SELECT statement against the database table using the unique id of the instance as the key.
    Dan

  • How can i extend the table control while transfering the data

    hi
    how can i extend the table control while transfering the data.

    Hi,
    For table control we have to handle the page down (P+, or what ever function codes are assigned to that activity) activity with our coding.
    Just check out this code:
    This is the bdc to update the XK01 transaction code (Vendor Creation).
    Here we will use table controls for bankings. Here Iam sending the coding and text files.
    Coding
    REPORT zprataptable2
    NO STANDARD PAGE HEADING LINE-SIZE 255.
    DATA : BEGIN OF itab OCCURS 0,
    i1 TYPE i,
    lifnr LIKE rf02k-lifnr,
    bukrs LIKE rf02k-bukrs,
    ekorg LIKE rf02k-ekorg,
    ktokk LIKE rf02k-ktokk,
    anred LIKE lfa1-anred,
    name1 LIKE lfa1-name1,
    sortl LIKE lfa1-sortl,
    land1 LIKE lfa1-land1,
    akont LIKE lfb1-akont,
    fdgrv LIKE lfb1-fdgrv,
    waers LIKE lfm1-waers,
    END OF itab.
    DATA : BEGIN OF jtab OCCURS 0,
    j1 TYPE i,
    banks LIKE lfbk-banks,
    bankl LIKE lfbk-bankl,
    bankn LIKE lfbk-bankn,
    END OF jtab.
    DATA : cnt(4) TYPE n.
    DATA : fdt(20) TYPE c.
    DATA : c TYPE i.
    INCLUDE bdcrecx1.
    START-OF-SELECTION.
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
    filename = 'C:\first1.txt'
    filetype = 'DAT'
    TABLES
    data_tab = itab.
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
    filename = 'C:\second.txt'
    filetype = 'DAT'
    TABLES
    data_tab = jtab.
    LOOP AT itab.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0100'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'RF02K-KTOKK'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '/00'.
    PERFORM bdc_field USING 'RF02K-LIFNR'
    itab-lifnr.
    PERFORM bdc_field USING 'RF02K-BUKRS'
    itab-bukrs.
    PERFORM bdc_field USING 'RF02K-EKORG'
    itab-ekorg.
    PERFORM bdc_field USING 'RF02K-KTOKK'
    itab-ktokk.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0110'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFA1-LAND1'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '/00'.
    PERFORM bdc_field USING 'LFA1-ANRED'
    itab-anred.
    PERFORM bdc_field USING 'LFA1-NAME1'
    itab-name1.
    PERFORM bdc_field USING 'LFA1-SORTL'
    itab-sortl.
    PERFORM bdc_field USING 'LFA1-LAND1'
    itab-land1.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0120'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFA1-KUNNR'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '/00'.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFBK-BANKN(01)'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '=ENTR'.
    cnt = 0.
    LOOP AT jtab WHERE j1 = itab-i1.
    cnt = cnt + 1.
    CONCATENATE 'LFBK-BANKS(' cnt ')' INTO fdt.
    PERFORM bdc_field USING fdt jtab-banks.
    CONCATENATE 'LFBK-BANKL(' cnt ')' INTO fdt.
    PERFORM bdc_field USING fdt jtab-bankl.
    CONCATENATE 'LFBK-BANKN(' cnt ')' INTO fdt.
    PERFORM bdc_field USING fdt jtab-bankn.
    IF cnt = 5.
    cnt = 0.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFBK-BANKS(01)'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '=P+'.  " Page down activity
    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFBK-BANKN(02)'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '=ENTR'.
    ENDIF.
    ENDLOOP.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFBK-BANKS(01)'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '=ENTR'.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0210'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFB1-FDGRV'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '/00'.
    PERFORM bdc_field USING 'LFB1-AKONT'
    itab-akont.
    PERFORM bdc_field USING 'LFB1-FDGRV'
    itab-fdgrv.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0215'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFB1-ZTERM'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '/00'.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0220'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFB5-MAHNA'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '/00'.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0310'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'LFM1-WAERS'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '/00'.
    PERFORM bdc_field USING 'LFM1-WAERS'
    itab-waers.
    PERFORM bdc_dynpro USING 'SAPMF02K' '0320'.
    PERFORM bdc_field USING 'BDC_CURSOR'
    'RF02K-LIFNR'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '=ENTR'.
    PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.
    PERFORM bdc_field USING 'BDC_OKCODE'
    '=YES'.
    PERFORM bdc_transaction USING 'XK01'.
    ENDLOOP.
    PERFORM close_group.
    **Flat files for the above code***
    Intial screen data file.
    1 63190 0001 0001 0001 mr bal188 b in 31000 a1 inr
    2 63191 0001 0001 0001 mr bal189 b in 31000 a1 inr
    Table control Data:
    1 in sb 11000
    1 in sb 12000
    1 in sb 13000
    1 in sb 14000
    1 in sb 15000
    1 in sb 16000
    1 in sb 17000
    1 in sb 18000
    1 in sb 19000
    1 in sb 20000
    1 in sb 21000
    1 in sb 22000
    2 in sb 21000
    2 in sb 22000
    Regards,
    Kumar.

  • How can i access the table GL_CODE_COMBINATIONS  !!

    I'm sorry ~ My English is poor ~~ understand me ^^
    I execute procedure APPS.GL_TEST but error occured
    ORA-00904:"GL_TEST";invalid identifier.
    but it execute well at orange (program that like toad)
    May be i can't access GL_CODE_COMBINATIONS table ~~
    I have to execute APPS.GL_CODE_COMBINATIONS_PKG.INSERT_ROW(
    X_ROWID => X_ROWID,
    X_CODE_COMBINATION_ID => X_CCID,
    it have GL_CODE_COMBINATIONS table
    so have to make account ccid
    How can i access the table GL_CODE_COMBINATIONS !!
    Thank you ^^
    --CREATE OR REPLACE PROCEDURE APPS.GL_TEST(EFFBUF OUT VARCHAR2, RETCODE OUT NUMBER)
    IS
    V_VAL NUMBER;
    BEGIN
    UPDATE GL_CODE_COMBINATIONS
    SET SEGMENT7 = 'TEST'
    WHERE CODE_COMBINATION_ID = 1169;
    END GL_TEST;
    Message was edited by:
    jake

    ORA-00904:"GL_TEAT";invalid identifier.spelling mistake?
    Is user APPS owner of the table GL_CODE_COMBINATIONS?
    If not, you need to grant the necessary privilege directly and not through a role

  • How can we update the last synchronization date and time..on SUP in sccm 2012 R2

    Hi,
        Can you any one please guide me how can i update the last  synchronization date & time in SUP on SCCM2012 r2 , some how its updated as future date and when ever i try to synch the SUP with disconnected WSUS its shows in the wsyncmgr.log 
    "Wakeup for a polling cycle " and  " Wakeupby inbox drop" and "Wakeup by SCF change"  
    Thanks 
    Balaji K

    You'll probably have to call CSS on this one as this not normal by any means. The messages you noted above are completely normal but if that's all you are seeing then there's an issue.
    Have you reviewed wcm.log and wsusctrl.log?
    Jason | http://blog.configmgrftw.com | @jasonsandys

  • HT1918 I cancelled a payment through PayPal. How do I update the payment for that charge?  I looked at my payment information and it has my credit card information.  I'm not sure where to update the PayPal part of payment.

    I cancelled a payment through PayPal. How do I update the payment for that charge?  I looked at my payment information and it has my credit card information.  I'm not sure where to update the payment that was associated with my PayPal account?  I am not sure what that paid for?  I am trying to process updates on my IPhone & IPad for apps. I have already downloaded. 

    Hi Xellana, and a warm welcome to the forums!
    I'm looking for information and pricing on possibly upgrading the processor from the PowerPC to Intel.
    While anything is possible if you had enough money... NOPE, you can't change the CPUs to Intel, nor can you get any faster PPC upgrades for it. It'd be far cheaper to buy a new IntelMac than to replace everything inside the G5, and I mean just about everything, then figure out how to machine the case & such to mount Intel Logic Board, Graphic Card & such.
    Sorry.

  • How can I update the firmware all at once

    I'm a tech support in a school, approximately our school has over 500 laptops, how can I update the firmware on all laptops at once?

    Apple Configurator is the software you want - and it's free from Apple. However, I'm dubious that firmware can be updated all at once.
    http://help.apple.com/configurator/mac/1.4.1/

Maybe you are looking for

  • Adobe Reader error message, "The application was unable to start correctly(0xc000007b)"

    Upon start up of my PC, an error message occurs that states, 'The application was was unable to start correctly(0xc000007b)" Reader isn't functioning properly and any programs that require it cannot be used(i.e. itunes, etc)  My computer operating sy

  • GoPro Hero 3 Black 4k and Adobe Media Encoder CS6

    As a current Creative Cloud member and a Premiere Pro user, I wanted to see if the Adobe Media Encoder can be used as an alternative to GoPro's Cineform Studio (free version), mainly as a batch encoder for use in Adobe Premiere Pro. The main issue wi

  • Settings in PRD system cannot be maintained ( T-code = IDLB )

    Hello, I need to make that the users can modify the legal range number of invoice document. You do this in the t-code < IDLB >  (this is a t-code for Chile). This can not be modified in PRD unless you change some parameters. I already make the follow

  • Business Process Step properties  not loading

    Hi All, I believe the problem is apparent enough from the topic itself . After i create a Business process and then decide upon the steps and later on when i try to load the properties of the individual steps its not getting loaded. i belive its not

  • Question regarding classes taken

    Hi all. Does anyone know where I can get proof that I took a class from Sun? I had taken a course, Fundamentals of the Java Programming Language, Java SE 6 (SL-110-SE6) (or whatever its equivalent was) sometimes between 2006 and 2008 (I know, I shoul