Union for concat every 3 rows

Hello to all
Please I need help for th folowing question:
WITH some_data AS (
   SELECT     'CNDMNL75P65L736C' cf,'' cp ,'' cr,    0 as I1,    1 as I2,    0 as I3    FROM dual
      UNION ALL
     SELECT     'PNZGCM74M24L736C'     ,'' cp ,'' cr,    5,    0,    0    FROM dual
       UNION ALL
     SELECT     ''    , '' cp ,'1' cr,         675,0,    0   FROM dual
       UNION ALL
     SELECT     ''    , '027113850273' cp ,'' cr,        0    ,32,     0  FROM dual
        UNION ALL
     SELECT     ''    , '12298850273' cp ,'' cr,      2,    0    ,0  FROM dual
         UNION ALL
     SELECT     ''    , '35798850273' cp ,'' cr,      0,    12    ,0  FROM dual
         UNION ALL
     SELECT     ''    , '627771888273' cp ,'' cr,      10,    2    ,0  FROM dual
      UNION ALL
     SELECT     'XDZGCM74M22L736C'     ,'' cp ,'' cr,    15,    0,    10    FROM dual
select * from   some_data;
CF       
CP   
CR
I1    I2    I3
CNDMNL75P65L736C  
0    1    0
PNZGCM74M24L736C  
5    0    0
1  
675    0    0
027113850273  
0    32    0
12298850273  
2    0    0
35798850273  
0    12    0
627771888273  
10    2    0
XDZGCM74M22L736C  
15    0    10
How can I get a something as; one(only) record for every 3 rows, like this   
CNDMNL75P65L736C            0    1    0PNZGCM74M24L736C            5    0    0        1    675    0    0 (first 3 rows)
     027113850273        0    32  0    12298850273        2    0    0    35798850273        0    12    0      (next 3 rows, )
     627771888273        10    2   0 XDZGCM74M22L736C            15    0    10                         (and so on )
Thanks in advance

For version 11g:
WITH some_data AS (
  SELECT 'CNDMNL75P65L736C' cf,'' cp ,'' cr, 0 as I1, 1 as I2, 0 as I3 FROM dual
  UNION ALL
  SELECT 'PNZGCM74M24L736C' ,'' cp ,'' cr, 5, 0, 0 FROM dual
  UNION ALL
  SELECT '' , '' cp ,'1' cr, 675,0, 0 FROM dual
  UNION ALL
  SELECT '' , '027113850273' cp ,'' cr, 0 ,32, 0 FROM dual
  UNION ALL
  SELECT '' , '12298850273' cp ,'' cr, 2, 0 ,0 FROM dual
  UNION ALL
  SELECT '' , '35798850273' cp ,'' cr, 0, 12 ,0 FROM dual
  UNION ALL
  SELECT '' , '627771888273' cp ,'' cr, 10, 2 ,0 FROM dual
  UNION ALL
  SELECT 'XDZGCM74M22L736C' ,'' cp ,'' cr, 15, 0, 10 FROM dual
select * from (
select a.*, mod(rownum-1,3)+1 rn, ceil(rownum/3) grp from some_data a
pivot(max(cf) cf, max(cp) cp, max(cr) cr, max(i1) i1, max(i2) i2, max(i3) i3
for rn in (1 a,2 b,3 c));
GRP
A_CF
A_CP
A_CR
A_I1
A_I2
A_I3
B_CF
B_CP
B_CR
B_I1
B_I2
B_I3
C_CF
C_CP
C_CR
C_I1
C_I2
C_I3
1
CNDMNL75P65L736C
0
1
0
PNZGCM74M24L736C
5
0
0
1
675
0
0
2
027113850273
0
32
0
12298850273
2
0
0
35798850273
0
12
0
3
627771888273
10
2
0
XDZGCM74M22L736C
15
0
10
For version 12c:
WITH some_data AS (
  SELECT 'CNDMNL75P65L736C' cf,'' cp ,'' cr, 0 as I1, 1 as I2, 0 as I3 FROM dual
  UNION ALL
  SELECT 'PNZGCM74M24L736C' ,'' cp ,'' cr, 5, 0, 0 FROM dual
  UNION ALL
  SELECT '' , '' cp ,'1' cr, 675,0, 0 FROM dual
  UNION ALL
  SELECT '' , '027113850273' cp ,'' cr, 0 ,32, 0 FROM dual
  UNION ALL
  SELECT '' , '12298850273' cp ,'' cr, 2, 0 ,0 FROM dual
  UNION ALL
  SELECT '' , '35798850273' cp ,'' cr, 0, 12 ,0 FROM dual
  UNION ALL
  SELECT '' , '627771888273' cp ,'' cr, 10, 2 ,0 FROM dual
  UNION ALL
  SELECT 'XDZGCM74M22L736C' ,'' cp ,'' cr, 15, 0, 10 FROM dual
select * from some_data
match_recognize(
  measures a.cf acf, a.cp acp, a.cr acr, a.i1 ai1, a.i2 ai2, a.i3 ai3,
           b.cf bcf, b.cp bcp, b.cr bcr, b.i1 bi1, b.i2 bi2, b.i3 bi3,
           c.cf ccf, c.cp ccp, c.cr ccr, c.i1 ci1, c.i2 ci2, c.i3 ci3
  pattern (a b{0,1} c{0,1})
  define a as 1=1, b as 1=1, c as 1=1
ACF
ACP
ACR
AI1
AI2
AI3
BCF
BCP
BCR
BI1
BI2
BI3
CCF
CCP
CCR
CI1
CI2
CI3
CNDMNL75P65L736C
0
1
0
PNZGCM74M24L736C
5
0
0
1
675
0
0
027113850273
0
32
0
12298850273
2
0
0
35798850273
0
12
0
627771888273
10
2
0
XDZGCM74M22L736C
15
0
10

Similar Messages

  • Sequence number - increment one for every 3 rows

    Dear All,
      I want to get a sequence number /group number, which increments 1 for every 3 rows. 
      For Example:
       Seq     Name   
        1          a
        1          b
        1          c
        2          D
        2          E
        2          F
        3          G
        3          H
        3          I
        4          abc
        4          aaa
        4          bbb
    Is there a function to do this?

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. Did you read the header of this forum?? But besides being rude, you are also ignorant.  A table has no ordering, so
    there is no concept of every third row. What are you using for a sort key? What happens when a new row is added to or deleted from this table? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Issue a commit statement for every 10000 rows updated

    Hi,
    I have a update statement, updating huge number of records.
    I wanted to issue a commit statement for every 10000 rows updated.
    Can this be done?
    Thanks,
    Dinesh

    user522952 wrote:
    Hi,
    I have a update statement, updating huge number of records.
    I wanted to issue a commit statement for every 10000 rows updated.
    Can this be done?
    Thanks,
    Dinesh Why do you want to issue commit statement frequently? Do you have a possible reason?
    If you think it will improve performance, you are 200% wrong. It will not improve performance it will only degrade performance. It will destroy the integrity of your data. It will screw you up big time.
    Ever heard of [ORA-01555 Snapshot too old|http://asktom.oracle.com/pls/asktom/f?p=100:11:4217554330904383::::P11_QUESTION_ID:275215756923] error? Your approach has a likely chance of getting that too.
    Do it in a single UPDATE. How big the table is does not matter. Do it in a single update, Oracle is fully capable of doing it.

  • How to make the shade for every other row?

    Hi,
    i want the rows in my report dispalyed as:
    row1: gray
    row2: white
    row3: gray
    row4: white
    row5: gray
    thanx

    Hello,
    Highlight every alternate row
    Highlight every alternate row
    Regards

  • URGENT - Change color for a set of rows in JTable

    Hello all,
    How can i set color for a particular set of row which are all having same values in a cell. If any other rows contains same value that should also be in different color.
    Example:
    I have 10 rows containing itemcode and taxes in JTable.
    1st, 2nd and 4 th row contains same value of Taxes -- It should be in a set of color. red
    6th and 8th row containing same value of Taxes -- it should be in a set of color blue
    other are in normal color. Kindly send the coding for the above. Advance thanks.
    Regards,
    N.A. Ramasubramani / Chennai.

    Hi,
    Here is how I do it... create a Vector of Vector or an array[row][col] containing colors for every cell (row,col). Create a custom Cell renderer in which you pass the color data variable. Then in the renderer you get the Row and Col and set the appropriated color for the background.
    JRG

  • How would I find the most common value every nth row in a column

    SCENARIO 1
    I have a column with a series of numbers in c1:c1000 as follows:
    2
    2
    3
    1
    1
    4
    2
    3
    1
    2...
    and I would like to find the most common value for every nth (in this case, second) row.
    SCENARIO 2
    Originally, I created a separate column in J and used this to find a value of 0 or 1 via a filter to label the rows odd or even. I was then going to create two separate columns, one for even rows of data and another for odd rows of data to separate them and perform functions on each column. But I do not know how to copy just the filtered data to one of the new columns to apply the MODE function (or any other for that matter).
    Perhaps my question should be: after applying a filter, how do i copy just the visible filtered data of every nth row to a new column in my spreadsheet while retaining the original column with all rows of data? 
    BACK TO SCENARIO 1
    If I do not need to go through this effort, I would just apply the MODE function (or AVERAGE or SUM) to every nth row in the original data column.

    Since Index and Offset were already taken, I used INDIRECT(ADDRESS()) in my example.
    Here's how I approached it:
    Expressions are as follows...
    Data Subset, Column A, Row 2: =IF(StartingRow :: A, 1, NSelector :: $A)
    Subsequent rows in Column A: =IF(ROW()<COUNT(Input :: $B)/NSelector :: A:$A+2, A2+NSelector :: $A, "")
    Data Subset, Column B, Rows 3
    throuth the last: =IFERROR(INDIRECT(ADDRESS(A+1, 2, ,,"Input")), "")
    Stats, Column A, Row 2: =IFERROR(MODE(Data Subset :: B), "No Mode")
    Stats, Column B, Row 2: =COUNTIF(Data Subset :: B, A)
    Lots of ways to skin this cat.
    Jerry

  • Update columns in Table A based on columns in Table B for more than 500K rows

    Guys,
    I need to update 9 columns in table A based on value from table B for for more than 500K rows.
    So what is best way to achieve this. I am thinking of writing a Procedure with cursor to update the rows of table A.
    When i googled about it, they say cursor will decrease the performance. So i have no clue how to go for this.
    Rough code which i though
    1) Procedure  with no parameter
    2) Will declare 9 variable to store value from cursor
    3) cursor will fetch row by row based on join condition between table a and table b
    4) i will pass column values from table B to variables
    5) will make an update statement for table A
    Please let me know if above method is correct or is there any other way to do this without using cursor.

    Guys,
    Below is the rough code i wrote as per my requirement. Does it look correct? As of now i dont have any platform to test it so any help with the below code is highly appreciated.  As i said i need to update more than 500K rows by matching Table
    A and Table B.  One more thing which i would like to add in below code, is to get log of all the rows that are in table B but not exist in table A.  Table A already has more than million data in it.
    Also not sure how the loop in below code willl run when @rowcount is become to zero?
    Please let me know if i need to consider performance related impact while running the script.
    GO
    SET SERVEROUTPUT ON
    CREATE PROCEDURE ONETIMEUPDATE
     DECLARE @cnt INT;
     SET @cnt = 1;
     DECLARE @MSG varchar(255);
     DECLARE @COUNT_VAR INT;
     SET @COUNT_VAR=0;
     WHILE @cnt > 0
        BEGIN
      Update TOP (50000) A
      Set A.Col1=B.Col1,
          A.COL2=B.COL2,
          A.COL3=B.COL3,
          A.COL4=B.COL4,
          A.COL5=B.COL5,
          A.COL6=B.COL6,
          A.COL7=B.COL7
      From TableA A
             Inner Join TableB B
             on A.ID = B.ID--ID
             WHERE A.Col1 <> B.Col1
                    OR A.Col2 <> B.Col2;
              SET @cnt = @@ROWCOUNT;
             IF @@ROWCOUNT=25000
               @COUNT_VAR=@COUNT_VAR + @@ROWCOUNT
               SELECT @MSG = CONVERT(varchar, @COUNT_VAR) + "Rows Updated" -- I WANT TO DISPLAY UPDATE after EVERY 25000 ROWS
              PRINT @MSG
      IF @@ROWCOUNT=0
         BEGIN    
               COMMIT
                       END
                    WAITFOR DELAY '00:00:01'  --wait for a second before the next update
                END;
     END;

  • Every other row (background color)

    I want to keep it simple and in css.  How can I get this to work properly so every other row has a yellowish background color with no gaps between the words.
    This is what I have but its producing an odd result.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
        margin: 0px;
        padding: 0px;
    div#footer{
        height:auto;
        background-color:green;
        clear:both;
        font-size:14px;
        width:800px;
    div#footer ul{
            margin:0;
            padding:0;
            list-style:none;
    div#footer li{
        width:155px;
        display:inline-block;
        text-align:center;
        vertical-align: top;
    /* horizontal line breaks */
    hr {
        border: 0;
        color: #323232;
        background-color: #323232;
        height: 1px;
        width: 95%;
        text-align: center;
    .even {
        background-color: #FF9;
    </style>
    </head>
    <body>
    <div id="footer">
            <ul>
            <li class="even">01/15/2011</li>
            <li class="even">Broadway Brewhouse</li>
            <li class="even">New Phila, OH</li>
            <li class="even">10pm</li>
            <li class="even">330-343-9231</li>
            <hr />
            <li>06/11/2011</li> <li>Edelwiess Inn</li> <li>Sugarcreek, OH</li> <li>10pm</li> <li>330-852-3750</li>    
            <hr />
            <li class="even">04/09/2011</li>
            <li class="even">Uhrichsville Moose Lodge (Open to the Public)</li>
            <li class="even">Uhrichsville, OH</li>
            <li class="even">TBD</li>
            <li class="even">740-922-9098</li>
            <hr />
            <li>01/15/2011</li> <li>Broadway Brewhouse</li> <li>New Phila, OH</li> <li>10pm</li> <li>330-343-9231</li>   
            </ul>
    </div>
    </body>
    </html>

    To create coloured backgrounds to every other row use this.
    #averages tr:nth-of-type(odd) {
      background-color:#ccc;
    Substitute the id of your table for mine and change the colour code to suit.

  • How to execute a same sequence number for the resulting dynamic rows

    Hi friends,
    I have a sequence and trigger(which will fire id for each and every row insert).
    My scenario is, If i update more than 5 rows at a time means, i need to set a same sequence number example(1) for all the 5 rows.
    Next time, if i update another 5 rows means, then i need to set a same sequence number (i.e) 2 for the next 5 rows.
    So, my updation will be dynamic(may be 2 ,5, 10 rows at a time), But i need to set a same sequence number for one of the column for all the rows that i update.
    Next time, if i update another set of rows means, then i need to set only the next sequence number(i.e) 2(assume that previously updated sequence for the before set of rows is 1) for another set of rows.
    Like that sequence has to update in a sequential manner for more than one set of rows in that column.
    How to achieve it friends.
    example
    id-----------------name
    1-------------------A
    1-------------------B
    1-------------------C
    1-------------------D
    1-------------------E
    2-------------------D
    2-------------------E
    2-------------------F
    2-------------------G
    3-------------------H
    3-------------------IBrgds,
    Mini

    Hi,
    You forgot to mention your version.
    If you want a trigger based solution, then in 10g you need two triggers
    1. A statement level trigger that takes sequence.nextval into a dummy variable that will not be used.
    2. A for each row trigger that uses sequence.currval.
    In 11g you should be able to write a single, composite trigger.
    If you want a solution with no triggers, it could look something like
    SQL> create sequence s start with 10;
    Sequence created.
    SQL>
    SQL> create or replace function s_wrapped
      2  return number
      3  as
      4     v number;
      5  begin
      6     select s.nextval
      7     into v
      8     from dual;
      9
    10     return v;
    11  end s_wrapped;
    12  /
    Function created.
    SQL> create table tab1 as (Select level x, cast(null as number) y from dual connect by level <= 5);
    Table created.
    SQL> update tab1
      2    set y = (select s_wrapped from dual)
      3   where x <= 3;
    3 rows updated.
    SQL> commit
      2  /
    Commit complete.
    SQL> select *from tab1
      2  /
           X          Y
           1         10
           2         10
           3         10
           4
           5
    SQL>Regards
    Peter

  • Shade every 10 rows in a table

    Im using DW CS3.
    Basically I have a large table of 300+ rows. Because the rows contain  data with a row number in each row (ranking, first column), the table  would be easier to read if every 10 rows were shaded. 1-10, 21-30,  41-50, and so on.
    Id like to do it in some sort of head or css way, rather than manually  apply the shading to each section of rows, mainly because I use a  sortable javascript for the table header and Id like the shading to  remain static in spite of the sorts.  The data is also fluid so there  might be 325 rows one day and 333 rows the next.
    Any way to accomplish this with html/css markup?  Thanks!

    Hi
    This will not work in IE8 or below without the selectivizr js file but you could use -
    table tr:nth-of-type(10n+1) {
      color: red;
    for IE8 and below you would require - http://selectivizr.com/, or one of the frameworks shown in the list of their home page.
    PZ

  • Making cuts every 2 rows in a table

    Hi again forum
            I have this requirement:
             1) In one table, for example:
                         |       h1      |        h2       |      h3    |
                         |       rA1    |        rA2      |      rA3   |
                         |       rB1    |        rB2      |      rB3   |
                         |       rC1    |        rC2      |      rC3   |
                         |       rD1    |        rD2      |      rD3   |
            2) I want to make cuts every 2 rows to summarize this colummns in a new row. Example:
                        |         h1     |        h2       |       h3    |
                        |         rA1    |        rA2     |       rA3   |
                        |         rB1    |        rB2     |       rB3   |
    New Row            |   rA1+rB1      |    rA2+rB2     |   rA3+rB3   |
                        |         rC1    |        rC2     |       rC3   |
                        |         rD1    |         rD2    |         rD3 |        
    New Row            |    rC1+rD1     |     rC2+rD2    |   rC3+rD3   |           
    Any idea, for insert the new row every n rows ?
    Thnks
    Josué Cruz
    Edited by: Josue Cruz on Aug 26, 2008 5:23 PM

    I don´t know how you have resolved this, but SAP recommends (and I recommen) to do this in backend/ ABAP (or Java) and display the result table with no scripting changes in the form.
    It spares time, effort and performance of the app.
    Otto

  • Query output skipping every other row

    I am using Coldfusion MX 7.0.1, and have two applications
    using the same datasource. In one, a SELECT query followed by a
    cfoutput lists all rows properly, but the following code (in the
    other app) only lists every other row of the query result set, for
    some reason:
    <cfselect name="Record_Group" multiple="no" size="4"
    required="yes" message="Select a Record Group...">
    <cfoutput query="RecordGroupQ">
    <cfif
    compare(#RecordGroupQ.RecordNum#,#Edit_origQ.acc_num#) eq 0>
    <option value="#RecordGroupQ.RecordNum#"
    selected>#RecordGroupQ.RecordNum#</option>
    <cfelse>
    <option
    value="#RecordGroupQ.RecordNum#">#RecordGroupQ.RecordNum#</option>
    </cfif>
    </cfoutput>
    </cfselect>
    The query is in the <head>, and is:
    <cfquery name="RecordGroupQ" datasource="arch_card">
    SELECT RecordNum FROM RecordGroups ORDER BY RecordNum ASC;
    </cfquery>
    Has anyone seen anything like this before?
    Thanks,
    Jason

    Dan Bracuk wrote:
    > As an aside, you don't want semi-colons in cfqueries.
    that's interesting... why is that so? i have been wondering
    about
    semi-colons lately myself, but could not find a definite
    explanation/rule/guide/best practice on whether to use them
    or not...
    could you please explain, Dan?
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com

  • Highlight every alternate row

    Hi,
    I have 2 queries, one for master and one for detail linked.
    In my paper layout, for my detail group I need to highlight every alternate row.
    I tried with creating a summary column in detail group
    and assigned formula as 'count' and selected reset group as the detail group, but i don't know what to assign for the source.
    also help me how the formatting trigger goes.
    thanks
    asha

    Hi Asha,
    There may be several ways to achieve this - "to highlight every alternate row" in your detail group.
    Here is just one example that I have tested - based on 2 linked queries (1 master and 1 detail).
    In your detail query, add the following column:
    mod(rownum,2)"Seq"
    to your SQL statement.
    This will give you values of 0 or 1 for alternate rows. ie row 1 "seq" will have a value of 1 and row 2 will have a value of 0, etc. This column does not need to be displayed in the layout.
    Now, you can add the following format trigger for each of the columns in the detail group:
    begin
    -- Automatically Generated from Report Builder.
    if (:mod_rownum_2 = '0')
    then
    srw.set_foreground_fill_color('red');
    srw.set_fill_pattern('solid');
    end if;
    return (TRUE);
    end;
    The above code was generated by using conditional formatting, setting the colour to "red".
    Hope the above helps.
    Regards,
    John

  • Delete every other row

    How can I automatically delete every other row in a Numbers spreadsheet?

    Thanks a lot.
    It's what we spell "Un rang sur deux".
    Automatic translator just replaced Engish words by French ones returning :
    Chaque autre rangée
    or
    toutes les autres lignes
    which had really no link with even/odd.
    It's a nice day, not only the sun shine but I learnt something new
    Yvan KOENIG (VALLAURIS, France) mardi 9 août 2011 16:42:55
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • Repeat table header after every 20 rows?

    Aloha gang,
    I have a spry table that loads an .xml file - the resulting
    table extends well 'below the fold' of the page
    is there a way to repeat the table header <th> every 20
    rows or so?
    bill - hawaii

    Hi Sergio,
    Thanks for the follow-up. I was thinking (after I made the original post) that I might be able to use a (pl/sql?) region and generate the report manually.
    Thanks,
    Mark

Maybe you are looking for

  • Network files not showing when saving a document in Word 2010

    I have some users setup where their local profile on their laptop syncs with our server so they can take the laptop home, work on files, bring it back to work and have it sync with files and folders when they get back. One user is able to open a docu

  • Starting Itunes after all neccesary installations

    I have installed Itunes 7.5 and Quicktime 7.4 successfully, but the problem lies in that when i start itunes after all the aforementioned installations are complete, and i have restarted my computer, a box pops up titled "Itunes Setup Assistant" that

  • Fuji Xerox Basic B&W Laser Priner P205B - Any chance?

    Just purchased this laser printer without checking driver support, doh! It seems a relatively new printer  and most google searches related to fuji/linux/drivers bring up older (more industrial heavy weight) models. http://www.fujixeroxprinters.com.a

  • Restrict by recipient

    Is it possible to restrict functionality to a group by the person they are collaborating with?  For example, if there were three groups, developers, testers, and support. And we wanted to set it up so: developers could only initiate a chat with suppo

  • Half my Bible has been raptured - will itunes give me another copy?

    I bought an (expensive) audio bible some time ago from itunes and listen to it occasionally. I'm not sure when it happened but about half the 33 file folders that go into making it up have been somehow emptied of content. The half-a-Bible has been sy