Merging multiple rows to one row

Hi,
I need a help.
I have the below table, table name is ITEM_LIST
ITEM VARCHAR2
COUNT_ITEM NUMBER
STATUS VARCHAR2
ITEM COUNT_ITEM STATUS
item1 1 in
item1 1 out
item1 2 out
item2 1 in
item2 1 in
item3 1 in
item3 1 out
And if I run,
SELECT ITEM, SUM(COUNT_ITEM), STATUS
FROM ITEM_LIST GROUP BY ITEM, STATUS
The below list is coming
ITEM SUM(COUNT_ITEM) STATUS
item1 1 in
item1 3 out
item2 2 in
item3 1 in
item3 1 out
This is the expected result but my real concern is to update the origin table(ITEM_LIST) the same as the above list.
Pleas help me.
Thank you in advance.
Message was edited by:
ginam

Instead of create ,rename and drop you can go for update, dellete
SQL> select * from item_list;
ITEM       COUNT_ITEM STATUS                                                   
item1               1 in                                                       
item1               2 out                                                      
item1               2 out                                                      
item2               2 out                                                      
item2               2 out                                                      
item3               1 out                                                      
item3               1 in                                                       
7 rows selected.
SQL> update item_list i
  2  set count_item = (select sum(count_item)
  3                    from item_list
  4                    where item = i.item
  5                    and status=i.status);
7 rows updated.
SQL> delete from item_list
  2  where rowid not in (select min(rowid)
  3                       from item_list
  4                      group by item,status);
2 rows deleted.
SQL> select * from item_list;
ITEM       COUNT_ITEM STATUS                                                   
item1               1 in                                                       
item1               4 out                                                      
item2               4 out                                                      
item3               1 out                                                      
item3               1 in                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Merging multiple rows in to a single row (when rows meet merging criteria)

    Hi 
    I have a scenario to merge multiple rows in to a single rows when the data in those rows fall in merge criteria .Below is how my data is 
    Now the merging logic for the above rows is , we need to combine multiple rows in to a single row when the data in those rows permits us to do in that way. Simply saying , its like sandwich where we combine multiple things to a single piece.The output for
    the above rows should be
    Here  we combined Row 1 ,2, 3 in to a single row as the data in those rows permits to merge in to single row. But the row 4 cannot be combined to any of those rows because the data in those rows doesn't permits us do a merge ( As the value of the column
    JobSource for the row 4 is different from the other rows ) .
    My original data has 56 columns , but for readability i kept only 9 columns. 
    can you please throw some idea on how to achieve this scenario. I know we need to use CTE for achieving this, but i am not able succeed in doing an iteration on multiple rows.
    Appreciate your response .

    Thanks for your reply .
    Rule for merging is simple . First of all there is no unique row identifier for each row , the fact table is not having an identity column in the database . I called row 1 , row 2  etc in my post above only to make better explanation of my scenario.
    The rule for merge is below. 
    1) we can combine only when the data in a column for one row is null & the data in same column for the other row is not null . It should also satisfy the condition where the data in other columns should conflict each other.
    2) Data for all columns for the merging rows should not be conflicting (i.e. we should not merge the rows when the data in a column is not equal to the same column in the other row
    ,considering not null value)
    Steps in merging the above source data :
    1) Consider the case of row 1 and row 2 in the source, we can combine these rows as the data is satisfying the rule 1 for columns (Jobsource,Flight, Package,Update,Iscancelled
    ,Result, Severity) and columns (JobID and RuleName ) fall under rule 2.  we merge these two rows in to a single row and keep in that in the table.
    2) Then the resulting row is again merged with the second row which is present above by applying the rule 1 and rule 2 . Below would be output of merge operation.
    Now there would be only two rows in the output . But these rows cannot be merged as the data doesn't satisfy the merge rules 2 . As Jobsource for the row 1 in the above output is "PresubmissionSource" which is not equal
    to "PostSubmission" jobSource which is in row 2. So these two rows are left unmerged .So the above two rows would be the output of merge operation on my source data.
    This process has to be repeated for all the rows in the table. As of now my table as 92 Million rows with 56 columns which need to be considered for merging rows. I replicated my scenario in 9 columns and 4 rows to understand better.

  • Merge multiple rows of same ID into Single row

    Hi All,
    I need the requirements of merging multiple rows of same ID as single row.
    My Table Data:
    ID     Language1 Language2 Language3 Language4
    1001 NULL         JAPANESE  NULL          NULL
    1001 SPANISH   NULL          NULL          NULL
    1001 NULL        NULL           NULL         ENGLISH
    1001 NULL        NULL           RUSSIAN    NULL
    Required Output Should be,
    ID     Language1 Language2 Language3 Language4
    1001 SPANISH    JAPANESE  RUSSIAN   ENGLISH
    Please help me to achieve this output.
    Tried grouping but its not working also producing the same result.
    Thanks.
    Live freee....Joy forever................ :)

    Try the below:
    create Table Test_Sample(ID int,Language1 varchar(50), Language2 varchar(50), Language3 varchar(50), Language4 varchar(50))
    Insert into Test_SAmple Values(1001,NULL,'JAPANESE', NULL, NULL),
    (1001,'SPANISH', NULL, NULL, NULL),
    (1001,NULL, NULL, NULL, 'ENGLISH'),
    (1001,NULL, NULL, 'RUSSIAN', NULL)
    Select ID,MAX(Language1),MAX(Language2),MAX(Language3),MAX(Language4)
    From Test_Sample
    Group by ID
    Drop table Test_Sample

  • Merge multiple rows into single row (but multiple columns)

    How to merge multiple rows into single row (but multiple columns) efficiently.
    For example
    IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
    23 asdc 1 Location USA NM ABQ Four Seasons 87106
    23 asdc 1 Stats 2300 91.7 8.2 85432
    23 asdc 1 Audit 1996 June 17 1200
    65 affc 2 Location USA TX AUS Hilton 92305
    65 affc 2 Stats 5510 42.7 46 9999
    65 affc 2 Audit 1996 July 172 1100
    where different attributes mean different thing for each Information_type.
    For example for Information_Type=Location
    Attribute_1 means Country
    Attribute_2 means State and so on.
    For example for Information_Type=Stats
    Attribute_1 means Population
    Attribute_2 means American Ethnicity percentage and so on.
    I want to create a view that shows like below:
    IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
    23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
    65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
    Thanks

    Hi,
    That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
    I hope this answers your question.
    If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're not formatted. Use \ tags, as described in the forum FAQ, below.)
    Explain, using specific examples, how you get the results you want from the data given.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).  This is always important, but especially so with pivots.
    See the forum FAQ {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to merge multiple spools in one PDF

    hi all,
    i have a requirement to merge multiple spools into one PDF.
    I have the code to merge 2 spools into one PDF but acc to my requirement this number can be any( say 100). hence i need  help to merge N number of spools in one PDF.
    Regards
    geeta gupta

    Take the data of all spools into a internal table then create a new spool with this data then downlad this data into pdf format.
    By this method you can download any number of spools into a single pdf file. Please see the below code
    Fetch spool number
    Select rqident from tsp01 into table g_t_data
    where...............
    Read sool data and take this data into a internal table
    Loop at g_t_data.
               Call program to read spool as follows
          SUBMIT rspolst2 EXPORTING LIST TO MEMORY AND RETURN
          WITH rqident = g_t_data-rqident
          WITH first = '1'
          Read memory where spool data is stored
          CALL FUNCTION 'LIST_FROM_MEMORY'
               TABLES
                    listobject = mem_tab
          Convert spool data to Ascii
          IF NOT mem_tab[] IS INITIAL.
            CALL FUNCTION 'LIST_TO_ASCI'
                 EXPORTING
                      list_index         = -1
                 TABLES
                      listasci           = g_t_text1(table type c length 10000)
                      listobject         = mem_tab(LIKE TABLE OF abaplist)
            APPEND LINES OF g_t_text1 TO g_t_text.
          ENDIF.
    ENDLOOP.
    Create new spool with internal table data
      NEW-PAGE PRINT ON
      KEEP IN SPOOL  l_keep(variable type c default u2018Xu2019)
      LINE-SIZE      300  
      LIST NAME      l_list (variable(30) TYPE c default 'combined_pdf')
      NO DIALOG.
      LOOP AT g_t_text.
        WRITE: g_t_text-data.
      ENDLOOP.
      NEW-PAGE PRINT OFF.
      COMMIT WORK.
    Fetch this spool number from TSP01
    SELECT rqident rqcretime FROM tsp01 INTO TABLE l_t_pdf(internal table having two fields rqident LIKE tsp01-rqident and rqcretime LIKE tsp01-rqcretime)
      WHERE   rqowner = sy-uname AND
                     rq2name = 'COMBINED_PDF'.
    Download spool data into pdf format
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
           EXPORTING
                src_spoolid   = l_t_pdf-rqident
           IMPORTING
                pdf_bytecount = l_size(variable type i)
           TABLES
                pdf           = g_pdf(table like table of tline)
      CALL FUNCTION 'GUI_DOWNLOAD'
           EXPORTING
                bin_filesize = l_size  "size
                filename     = l_data
                filetype     = 'BIN'
           TABLES
                data_tab     = g_pdf.
    Hope this will help you.

  • Text issues merging multiple pdfs into one pdf

    Hello, when I merge multiple pdfs into one pdf document my text is missing or garbled.  I spent hours yesterday trying to figure this out, from insuring the text was embedded and print setting were correct.  Please help!!
    Using Adobe Pro 9.0
    Thanks,
    Faith

    Acrobat Pro is the application you use for working with PDFs, making minor edits, combining multiple PDFs into a single file, extracting or replacing pages, doing fancier form work than ID has the ability to produce, and even creating PDF from a number of other file formats. I'm not sure your question about maintaining the quality of your photos is really applicable -- it would depend on how youare getting from the photo to PDF to begin with. The use of Acrobat in and of itself won't be the determiner.
    That said, I couldn't live without Acrobat Pro in my workflow. Since you are on CS5.5 you have a couple of options. You could purchase a subscription to Creative Cloud (at a discount for the first year), which would give you access not only to Acrobat, but all of the other programs and tools included in the suite, but you pay a monthly or yearly fee, or you can buy a standalone perpetual license to either Acrobat Pro or Acrobat Standard (I didn't realize Standard was still an option, and you might not need all the features of Pro -- you can compare at http://www.adobe.com/products/acrobatpro/buying-guide.html).

  • Merge multiple pictures into one picture like Photoscape?

    Looking for imac software like Photoscape which can merge multiple pictures into one.  Thanks!

    PhotoShop Elements is a good one
    LN

  • ADF - Merge multiple row

    Hi,
    I would like to know if i can update (merge) multiple line at once.
    typical situation : i have a master(form)-detail(table) page, i can modify one field in the detail table for each row
    i've made a "merge" button which update one row in db ( using mergeStudent(Student) databinding command
    i use the binding data of selected row to do this and it work very well. ( currentRow.dataprovider )
    now what the best ( and easier) solution to update ( merge ) every row of this table
    i've thought that i can create a "mergeStudents(list<Students>" function in my Ejb but i don't know if there s a binding object which send the full list
    Thanks and sorry for my english.

    Select C1,C2, C3,C4,C5 FROM
    (SELECT C1,C2,Max(C3) Over() as C3,C4,C5 FROM yourtable) t
    WHERE C4<>'0'

  • Oracle query - Merging multiple rows into a single row output

    Hi All,
    I have to have a multiple row output to be converted into a single row output.My current output looks as follows:
    ID YR INC_CODE OFFN SCHOOLNO
    8006 2002 00175 SC03 12
    8006 2002 00175 DC06 12
    8006 2002 00175 DC03 12
    8006 2002 00175 DC02 12
    ID,INCIDENT CODE,OFFENSE are all Primary keys
    So I need the output as follows:(IN ONE ROW)
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 SCHOOLNO
    8006 2002 00175 SC03 DC06 DC03 DC02 12
    Can you help me on this since have been spinning the wheel and this has to be a query since will have couple of tables join to produce a materialized view.
    Thanks in advance

    Hi Nigel,
    Thanks for the reply I tested out the portion having the decode and I get the output as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 -----------------------
    8982 2002 2175 DOC02-------------------
    8982 2002 2175 DOC03------------
    8982 2002 2175 DOC06-------
    8982 2002 2175 SCV03
    There is no value as max for OFFN and each INC_CODE MAY HAVE UP TO A MAX OF 5 OFFN.My query is as follows:
    select distinct STU_STUDENT_ID, INC_BEG_SCH_YR,INC_INCIDENT_CODE
    , decode(rank() over (partition by INC_CODE order by OFFN),1,OFFN,null) as offn1
    , decode(rank() over (partition by INC_CODE order by OFFN),2,OFFN,null) as offn2
    , decode(rank() over (partition by INC_CODE order by OFFN),3,OFFN,null) as offn3
    , decode(rank() over (partition by INC_CODE order by OFFN),4,OFFN,null) as offn4
    , decode(rank() over (partition by INC_CODE order by OFFN),5,OFFN,null) as offn5
    from stu_offn where
    stu_offn.ID = '8982' and stu_offn.INC_CODE = '2175'
    (****Where clause is just given to just check a value)
    So as you know I need to just have all the OFFN in a single row ie as follows:
    ID YR INC_CODE OFFN1 OFFN2 OFFN3 OFFN4 OFFN5
    8982 2002 2175 DOC01 DOC02 DOC03 DOC06 SCV03
    Can you just give me a step by step procedure to go through this and the table in this case is just 'STU_OFFN'
    Thanks for the earlier reply appreciate it!
    ****Sending this again to show the exact way the output is coming

  • Merging multiple rows into a string without loop

    Hi,
    Wanted to know if there is a way we can merge the result set for a query(single column) into a string ?
    For example, I have the following query which returns multiple rows:
    SELECT organization_code
    FROM mtl_parameters
    WHERE oganization_id IN ( 1,2,3)
    Lets say the result set for this is :
    A
    B
    C
    I want the data as A,B,C
    Basically I will be fetching the organization_ID from a diff sub query. I know I can do it using for loop and keep appending the values.
    But wanted to know if there is any easier way of doing it.

    Try this
    SELECT ''||SUBSTR (SYS_CONNECT_BY_PATH (organization_code , ','), 2)||'' csv
          FROM (SELECT organization_code
    , ROW_NUMBER () OVER (ORDER BY organization_code
    ) rn,
                       COUNT (*) OVER () cnt
                  FROM mtl_parameters
    WHERE oganization_id IN ( 1,2,3)
         WHERE rn = cnt
    START WITH rn = 1
    CONNECT BY rn = PRIOR rn + 1;

  • How do you merge multiple songs into one album?

    When I added a downloaded album to iTunes, it created one album for each track. How do I merge all of these albums/tracks into one album?

    Some albums will fracture into a million pieces if you have different artist names. How the columns are sorted can effect this.
    If it is a multiple artists on one album select 'Compilation' in the options section for all of the songs on the album. 
    NOTE: You need to have multiple items selected to set this flag!

  • When merging multiple pdf into one all pages are blank

    I am currently using Adobe Acrobat Version 10.1.13.  When I try to merge multiple pdf's into one all pages are blank.  I ran the Repair Adobe Installation and this did not fix the problem.
    Please provide me with any help/suggestions you may have.
    thank you in advance for your time.

    Hey tricon5757,
    Could you please let me know how have you tried merging PDFs.
    Also, try choosing 'Document > Insert Pages' option and combine PDF one after the other.
    Let me know if this works.
    Regards,
    Anubha

  • Merging Multiple Artists Into One Album

    Ok so I donwloaded a CD called Buzz Cuts with alot of great artisits. Now my problem is there are 30 songs and Itunes is showing 30 different albums even though they are all from the same CD. Its messing up because of all the different artists. How can I merge them all into one album called Buzz Cuts. Or is there a way to sort them. Its a pain having 30 extra cds at the top screen. Please help.

    All of this can be adjusted by simply right clicking a song and selecting "Get info." Under the info tab, you can customize things like crazy. For instance, you can insert into the "album" field the title of the compilation.

  • Merge multiple tables into one for export to excel

    I've got a few tables in Numbers, and I've spent ages making them all look the same, then when I exported to an excel file, they split up into seperate tables. How can i merge all these into one table so they can all be viewed in Excel, without losing the cell shading/borders etc?
    I tried just copying/pasting the tables into a new blank table, but this doesn't paste the borders etc...
    Cheers
    Adi

    Adi,
    Fill color will copy and paste, as will Text styles, but borders will not when pasting into another table. My suggestion for future work is to not use fancy borders, or don't apply them until you have combined the tables.
    If you would like Apple to consider changing the behavior of borders during Copy/Paste operations, you can leave Feedback for them under the Numbers Menu.
    Jerry
    Message was edited by: Jerrold Green1

  • Merging multiple Rows in to one In Table.

    Hi Friends,
    In Our application we are maintaining one table which has 12 rows with 12 different values (All are Read only).
    Based On Some condition the number of rows changes. The maximum number of rows possible with diffrent vaues is 11. but as soon as the number of rows become 12 all the values become similar. means all the values are same. so what i want is, in this condition i want to display only one row instead of 12 rows. how can i marge those 12 rows..??
    Thanks & Regards
    Jeetendra

    I think you just need to break down the approach into two:
    1) basic merging of data based on the categories you mentioned. put them in an a Collection family object and merge from there.
    2) dynamic UI programming for the table
    That's what I see at least. Goodluck!
    Regards,
    Jan

Maybe you are looking for

  • How to create recovery media from HDD recovery image?

    When I tried to recover a fresh Windows from HDD recovery my little son stopped the proccedure by accident. When I tried to restart I get the message bootmgr is missing. I have a copy from HDD recovery file but din not create a recover DVD. The quest

  • How can I export a PDF photo portfolio with a clean cover page?

    Hello, I have compiled a photo portfolio in Bridge and wish to have a clean cover page that does not have the contact info, copyright, etc., that exists on the photo pages.  The cover page was created in Ps and imported into Bridge. From what I can s

  • In PR only base uom can be used - Why not order unit ?

    Hi All, When I create PR for raw material, SAP by default takes the base UOM. But our stack holders wants to use Order unit in the PR. What is the setting required to use order unit in PR. If this can't be done - what is the note number to support th

  • Screen is green please help

    when I go to youtube or even on my facebook the video's do not play they are a green screen and I can hear what's going on but just don't have a video pleas help

  • Bulk removal of contacts

    So, the bulk import works great to add contacts. Is there anyway to automatically remove contacts when staff leave the company? We currently use office communicator and it allows us to remove the contacts from everyones lists. Granted it's not hard t