Pivot number lines number Variable fixed columns

Hello world

Here is my desired result.

Consolidation of less than 18 years 18-25 26-35 36-45 46-55 of 55
Unit 0 32 57 12 15 86
Unit 1 85 14 0 32 66 B
Unit 77 69 91 33 7 C 0
54 17 8 2 51 61 D unit

Where do you see zeros in the age categories that no line is to provide information.

Here is my entry.

WITH my_categories AS (SELECT 1 AS 'ID', "less than 18 years of age" AS "CATEGORY")
OF THE DOUBLE
UNION ALL
SELECT 2, 18-25'
OF THE DOUBLE
UNION ALL
SELECT 3, 26-35'
OF THE DOUBLE
UNION ALL
SELECT OPTION 4, 36-45'
OF THE DOUBLE
UNION ALL
SELECT 5, 46 - 55'
OF THE DOUBLE
UNION ALL
SELECT 6, 'more than 55'
THE DOUBLE).
AS my_table
(SELECT ' unit has "AS"UNIT", 2 AS 'Stuff', AS 'COUNT' 32)
OF THE DOUBLE
UNION ALL
SELECT 'Unit A', 3, 57
OF THE DOUBLE
UNION ALL
SELECT "Unit A", 4, 12
OF THE DOUBLE
UNION ALL
SELECT "Unit A", 5, 15
OF THE DOUBLE
UNION ALL
SELECT 'Unit A', 6, 86
OF THE DOUBLE
UNION ALL
SELECT 'Unit B', 1, 1
OF THE DOUBLE
UNION ALL
SELECT 'Unit B', 2, 85
OF THE DOUBLE
UNION ALL
SELECT 'Unit B', 3, 14
OF THE DOUBLE
UNION ALL
SELECT 'Unit B', 5: 32
OF THE DOUBLE
UNION ALL
SELECT 'Unit B', 6, 66
OF THE DOUBLE
UNION ALL
SELECT 'Unit C', 1, 77
OF THE DOUBLE
UNION ALL
SELECT 'Unit C', 2, 69
OF THE DOUBLE
UNION ALL
SELECT 'Unit C', 3, 91
OF THE DOUBLE
UNION ALL
SELECT "Unit C," 4: 33
OF THE DOUBLE
UNION ALL
SELECT 'Unit C', 5, 7
OF THE DOUBLE
UNION ALL
SELECT "unit D ' 1, 54
OF THE DOUBLE
UNION ALL
SELECT "unit D", 2, 17
OF THE DOUBLE
UNION ALL
SELECT "unit D", 3, 8
OF THE DOUBLE
UNION ALL
SELECT "unit D", 4, 2
OF THE DOUBLE
UNION ALL
SELECT "unit D", 5, 51
OF THE DOUBLE
UNION ALL
SELECT "unit D ', 6, 61
THE DOUBLE)
-SELECT * FROM MY_CATEGORIES
-SELECT * FROM MY_TABLE
SELECT *.
FROM my_table
JOIN THE
my_categories
ON my_categories.id = my_table.category_id
ORDER BY my_table.unit, my_table.category_id

Any suggestions?

Thanks in advance for your help,

Lou

Hey, Lou,

See [this thread | http://forums.oracle.com/forums/message.jspa?messageID=3227388#3227388] to find out how the pivots.
This example uses COUNT; in this issue, you will want to use MIN or MAX instead.

If the number of columns is fixed and that you can hard-code the column headings in the query, then you won't need to use dynamic SQL statements.

Published by: Frank Kulash, June 17, 2009 16:50

Tags: Database

Similar Questions

  • A formula allows the last number in a column?

    Is it possible to have a work formula with the last number in a column or line automatically?

    For example:

    Col Col B

    Jan                    20

    21 Feb

    Mar                    18

    Apr                    16

    May

    Jun

    Jul

    I would like to be able to have a use form the last number in column B. I'll add the numbers to the list each month. And the sort numbers is not realistic because of the aspect from month to month.

    I know that I can change the formula of each month, but automatic is less prone to errors. It doesn't seem to be a function of 'last '. I work in the latest version of numbers and prefer not to spend at Excel.

    Any suggestions?  Thank you.

    .. Doug

    If you have no empty cells in the column, you can do something like this:

    = INDEX (array 1::B, COUNTA (table 1::B) + 1).

    The + 1 is necessary if there is a header row.

    SG

  • ORA-02256: number of referencing columns must match the referenced column

    The following script produces

    ORA-02256: number of referencing columns must match the referenced columns, can't think of any reason, someone has an idea?

    Please help, I am stuck on an assignment...!

    Capture.PNG

    drop table qualitycheck;

    drop table distribution;

    Manager to move table;

    CREATE THE TABLE MANAGER)

    MgrID number (4),

    mfirstname varchar2 (30),

    msurname varchar2 (30),

    Primary key (mgrid)

    );

    CREATE DISTRIBUTION TABLE)

    ProdID number (4) CONSTRAINT NN_PRODUCT_prodid NOT NULL,

    MgrID number (4) CONSTRAINT NN_MANAGER_mgrid NOT NULL,

    Primary key (prodid, mgrid)

    CONSTRAINT FK_ALLOCATION_MANAGER_mgrid Foreign Key (mgrid) REFERENCE MANAGER,

    CONSTRAINT FK_ALLOCATION_PRODUCT_prodid Foreign Key (prodid) REFERENCES PRODUCED

    );

    CREATE TABLE QUALITYCHECK)

    ProdID number (4) CONSTRAINT NN_ALLOCATION_prodid NOT NULL,

    MgrID number (4) CONSTRAINT NN_ALLOCATION_mgrid NOT NULL,

    number of weekno (2),

    Partition number (1),

    Primary key (prodid, mgrid, weekno)

    CONSTRAINT FK_QUALITYCHECK_PRODUCT_prodid Foreign Key (prodid) ATTRIBUTION of REFERENCES,

    CONSTRAINT FK_QUALITYCHECK_MANAGER_mgrid Foreign Key (mgrid) ASSIGNMENT of REFERENCES

    );

    Hello

    Reason is the primary key of the table that is assigned prodid, mgrid, but you try to create the foreign key columns separately.

    Try which follows and this should work:

    CREATE TABLE QUALITYCHECK (
      prodid number (4) CONSTRAINT NN_ALLOCATION_prodid NOT NULL,
      mgrid number (4) CONSTRAINT NN_ALLOCATION_mgrid NOT NULL,
      weekno number (2),
      score number (1),
    
    Primary Key (prodid,mgrid,weekno),
    
    CONSTRAINT FK_QUALITYCHECK_PRODUCT_FK Foreign Key (prodid, mgrid) REFERENCES ALLOCATION
    );
    
  • Pivot lines not converted into columns?

    Hello

    I did pivot amount lines successfully.

    But the lines not converted into columns while I'm working on the lines of pivot columns.


    err1.jpg


    err2.jpg


    Please help me.

    Thanks in advance,

    A.Kavya

    Hello

    Take a look at this link:

    ODI gurus: ODI PIVOT - ROWS to COLUMNS

  • The number of the column datatype story

    The number of the column datatype story

    Hello

    We have the existing DB table with created_by and updated_by NUMBER data type columns. I created EO/VO using the same table.

    As and when we click on + symbol for (insert a newline) browser of Oracle business components... Get the following error message

    Exception in thread "AWT-EventQueue-0" oracle.jbo.domain.DataCreationException: Houston-25009: failed to create an object of type: java.lang.Long type: java.lang.String with value: covering

    As the old huge with content DB table. I'm sure, that I can not change the data type of these two columns in DB.

    I have a possibility to exclude these two columns when creating entity object.

    It would be great, if you can suggest other options to avoid this problem by including these two columns.

    JDev - 11.1.1.5.0

    Thank you

    LSs

    Now, I could solve the problem as you have suggested.

    Thank you

    MSR.

  • Is there a limit in the number of custom columns that can be created?

    Hi Experts,

    Is there a limit in the number of custom columns that we can create in the informatica mappings that get out us of the box? What is the best practice for Oracle? Please let me know.

    Thank you
    Kris

    For performance purposes, it is recommended that you do not enter a columns more than 254 to dimension to the fact table.

    http://download.Oracle.com/docs/CD/E12513_01/doc/BIC.101/e12652/dacdesignetl.htm#i1059392

    Wrong forum btw: Applications Business Intelligence

  • How do I rotate my result of a query from a line to a SQL column?

    Hey, guys:

    Is it possible that I can rotate my result of a query from a line to a SQL column?

    It's a certain type of pivot example
    Instead of
    DEPTNO DNAME
    -------- ---------------
    10 accounting
    It would be
    DEPTNO: 10
    DNOM: ACCOUNTING

    Hello

    When you have N columns to rank 1 and you want to display in the form of 1 column on several lines, it's called Unpivoting . Here's a way to do it:

    WITH     cntr     AS
    (
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 2     -- number of columns to be unpivoted
    )
    SELECT     CASE c.n
             WHEN  1  THEN  'DEPTNO'
             WHEN  2  THEN  'DNAME'
         END || ':'        AS label
    ,     CASE c.n
             WHEN  1  THEN  TO_CHAR (d.deptno)
             WHEN  2  THEN  d.dname
         END || ':'        AS val
    ,     d.deptno               -- PK, if needed
    FROM         cntr        c
    CROSS JOIN  scott.dept  d
    WHERE   deptno = 10               -- or whatever
    ;
    

    The query above works in Oracle 9.1 or more.
    From Oracle 11.1, you can also use the SELECT... Function of the UNPIVOT operator.

  • Select all the lines of a specific column

    Hello

    I have a complete excel data file and I want to display in the control table labview

    the number of rows in the excel file is not defined, but I know what colume there is.

    so now im using report generation tools read my excel file by setting the line position and colume, but if I put '-1' on the two lines which is of all package read and the column position, an error occurs.

    any way to solve?

    64864050 wrote:

    Hello

    I have a complete excel data file and I want to display in the control table labview

    the number of rows in the excel file is not defined, but I know what colume there is.

    so now im using report generation tools read my excel file by setting the line position and colume, but if I put '-1' on the two lines which is of all package read and the column position, an error occurs.

    any way to solve?

    There is no problem with the index of line-1, as long as you read one column.

    To read several columns, you must set the start and the end of the table block. Since you know your number in the column, simply determine the line number. You can use the Row.vi last Excel get, as shown below.

  • Create model XMLP for lines in 2 different columns?

    Hi all, is it possible to create a model of XMLP which shows the same group of data, but in 2 different columns, i.e. the left column display (say) first 10 lines and the right column display lines of the 11th-20th?

    The XML source contains only the total number but no individual line number.

    Thank you very much!

    I have 2 columns of the table.
    And in each column of a table. Round table can have at a time for each

  • Numbering of the lines based on two columns

    Hello world

    I´d would like to know if there is a way to achieve the numbering shown in the second table below indicating only Oracle native functions, like ROW_COUNT() on the partition, etc.

    I m using Oracle 10 g.

    The logic used is:
    From 1, increment one each time that the ORIGIN is identical to the FIRST ORIGIN of the line (ID) group.
    ID    ORIGIN    DESTINATION    ORDER
    ------------------------------------
    1     A         B              1
    1     B         A              2
    1     A         B              3
    1     B         C              4
    1     C         A              5
     
    ID     ORIGIN    DESTINATION    ORDER    NUMBERING
    --------------------------------------------------
    1      A         B              1        1
    1      B         A              2        1
    1      A         B              3        2
    1      B         C              4        2
    1      C         A              5        2
    In order to compare the ORIGIN of each line with the FIRST ORIGIN of the group, I used the function LAG to create a column that will be the FIRST ORIGIN of the value in the group.

    However, I was not able to number the lines as shown above (column NUMBERING).

    Any help will be much appreciated.

    --------------------------------------------------------------------------------------------------------------

    Test query:
    WITH T AS
    (
      SELECT 1 ID, 'A' ORIGIN, 'B' DESTINATION, 1 ORDERING FROM DUAL UNION ALL
      SELECT 1 ID, 'B' ORIGIN, 'A' DESTINATION, 2 ORDERING FROM DUAL UNION ALL
      SELECT 1 ID, 'A' ORIGIN, 'B' DESTINATION, 3 ORDERING FROM DUAL UNION ALL
      SELECT 1 ID, 'B' ORIGIN, 'C' DESTINATION, 4 ORDERING FROM DUAL UNION ALL
      SELECT 1 ID, 'C' ORIGIN, 'A' DESTINATION, 5 ORDERING FROM DUAL
    )
      SELECT T.ID
           , T.ORIGIN
           , T.DESTINATION
           , T.ORDERING
           , LAG (T.ORIGIN, T.ORDERING -1, 0) OVER (PARTITION BY T.ID
                                                        ORDER BY T.ID
                                                               , T.ORDERING) FIRST_ORIGIN_OF_GROUP
        FROM T
    ORDER BY T.ID
           , T.ORDERING

    Hello

    Here's one way:

    WITH     got_first_origin     AS
    (
         SELECT     id, origin, destination, ordering
         ,     FIRST_VALUE (origin) OVER ( PARTITION BY  id
                                          ORDER BY         ordering
                                     ) AS first_origin
         FROM    t
    )
    SELECT     id, origin, destination, ordering
    ,     COUNT ( CASE
                        WHEN  origin = first_origin
                  THEN  1
                    END
               )     OVER ( PARTITION BY  id
                           ORDER BY      ordering
                   ) AS numbering
    FROM     got_first_origin
    ;
    

    This assumes that the combination of id and order is unique. Within an id, you place your order does not have to be consecutive integers, or something like that.

    Analytical functions cannot be nested (the argument of the function of COUNTY anlytic can not call the analytical FIRST_VALUE function); The subquery is necessary.
    You could do something with a LAG, as you have tried, rather than FIRST_VALUE, but you would still need a subquery, for the same reason.

  • Is it possible to have a fixed column width and a URL link?

    I'm trying what a popup link on a column in a SQL report, but also have the report column a certain width. Can I have or not however at the same time.

    What I did was created a SQL report, published a column and he gave a URL redirect (page in application) as usual.

    Fixed column width, I used:
    <div style="width:250px; height:54px; overflow:hidden" title="#Comments#">#Comments#</div>
    The formatting of column / Expression HTML

    And for the URL of the popup, I used:
    onclick="window.open(this.href,'_blank','resizable=0,scrollbars=0,width=650,height=300,menubar=0,location=0');return false;" title="Comments"
    On the column link / link attributes

    Hello

    It is possible that there is an error in your code - shows your snapshot & 523. -the & and the. should not be there. If you have changed to that of & APP_ID., then you don't need the & or the. but, normally, you should leave as & APP_ID. as the value for this will change when you move from dev to test for prod and Apex will automatically replace this string with the number of correct application.

    Andy

  • Issue temporary Variables and columns of the Table

    Hello

    I have a table with two columns advanced region and add line features.

    First column is a messageChoice and the other column has two grains of messageLovInput. And according to the value of messageChoice that I have to make a fake messageLovInput.

    Now, I have attached SPEL with messageLovInput and attached to a partial action of fire with messageChoice.
    For what I create a PVO and added two variables in it.

    But now when I select any value of choice message its not showing regions lOV properly. It always shows lov single area only. No other one based on the value selected in the drop-down list.



    I hope I am clear.

    Satya

    Satya

    Rather than create a PVO I create transient attributes in the area of advanced table VO itself. So that you can get the reference to the line for each line.

    Thank you
    -Anil
    http://oracleanil.blogspot.com/

  • I get error filter Render - error in initialization of symmetry script: line 43: Variable name expected. Help, please.

    Hi all

    I left creative cloud. Check the updates.

    That an activity that could affect system files was to uninstall applications CC, keeping the CC 2014 apps only.

    I need to use the flame of rendering filter, but I get the following error

    Error in the initialization of symmetry script: line 43: Variable name expected

    I get this error with tree to make and restore frame.

    A response will be appreciated

    Thank you

    Thank you for your response. I just came back good. After making sure that I got all the updates, I quit and restarted photoshop and it does the trick.

  • Matrix of distances: selection of values with the number of the column as a variable

    Hi all

    You wonder if SQL can do natively, let's go.

    I have a static table with the same amount of rows and columns, that changes forever; It represents the distances between locations (e.g. countries).
    It's basically a distance matrix (you can find a good example on Wikipedia ).

    My SQL statement must extract the distances of this matrix, based on the IDS of countries located in another table.
    Select a field is simple:

    SELECT * from cdistances where countryid =
    (select countryid from countries where upper (country) = upper (& getcountry));

    When I run the present, I get a line of all distances to all countries of the country I go when asked. But I would limit the outcome of a country of destination that I entered.

    Of course, a CASE statement would solve this nicely, but since we are talking more than 200 countries, which will become unmanageable.

    Another method that I approached is to use a variable as a column, as below:

    SELECT & getdestination of cdistances where countryid =
    (select countryid from countries where upper (country) = upper (& getcountry));

    It works well when I get directly the column identifier (manually from the keyboard) but I would like to automate even further.
    My names of columns in the matrix of distances are named as follows:
    countries1, countries2, countries3... country200 - where the number ID the real country, preceded by the constant string 'country '.
    So I tried to define a variable as a concat between 'country' and another variable:
    def getd2 = concat ("D2C", & testcountryid);
    Of course, it does not; the output of the script is:

    old: def getd2 = concat ('country', & testcountryid)
    New: def getd2 = concat ("country", 12)

    where I expected to be 'country12.

    I'm so little loss of thoughts. Maybe I'm pushing my train of thought in the wrong way, so I guess the general question would be: how to select a specific column of a table based on information outside the SQL statement dynamically?

    Hello

    I'm still confused.
    Is your table called chessking or testdistances, or you have 2 separate tables?

    I'm guessing that your single table is testdistances, and you want to pass a list of countryids, such as that of 3.1 to a query and get results as follows:

    `COUNTRYID  DISTANCE3  DISTANCE1
    ---------- ---------- ----------
             1         18         15
             3         13          1
    

    If so:

    DEFINE     country_list = "3,1"
    
    -- Preliminary Query, to set column_list
    COLUMN     column_list_col     NEW_VALUE column_list
    
    SELECT     'distance' || REPLACE ( '&country_list'
                               , ','
                         , ',distance'
                         )          AS column_list_col
    FROM    dual;
    
    -- Main Query
    SELECT     countryid
    ,     &column_list
    FROM     testdistances
    WHERE     countryid     IN (&country_list)
    ;
    

    Sorry, I'm out of time now. I'll explain more in a few hours.

  • Column for the 11 g function Pivot number formatting

    Hello

    I have a question regarding the formatting of data in a PivotTable.
    I have the pivot:

    Select * from
    (
    Select
    ENAME,
    EMPLOYMENT,
    Sal Sum (SAL)
    from EMP
    Group by ename, job
    )
    Pivot
    (
    Sum (SAL) as salary for (JOB) in ('SELLER', 'MANAGER')
    )

    and the results:
    -------------------------------------------------------------------------------

    'SELLER' _SALARY 'MANAGER' _SALARY ENAME
    JONES - 2975
    ALLEN 1600-
    FORD-
    CLARK - 2450
    MILLER-
    WARD - 1250


    How can I format the results of the Pivot to have salary format as for thousands comma ',' as: 'select TO_CHAR(500000000000,'999G999G999G999G999G999G990','NLS_NUMERIC_CHARACTERS=.,') from dual; Is this possible?

    I can't use to_char() function is central, because it is not an aggregate work so TO_CHAR (SUM (.)) is not possible and the base SUM (TO_CHAR (.)) because its a mistake?


    Help, please.


    Kind regards
    Alex
    select
    ENAME,
        TO_CHAR("'SALESMAN'_SALARY",'999G999G999G999G999G999G990','NLS_NUMERIC_CHARACTERS=.,') salary
    from
    (
       select
       ENAME,
       JOB,
       sum(SAL) sal
       from EMP
       group by ename, job
    )
    pivot
    (
      sum(sal) as Salary for (JOB) in ('SALESMAN','MANAGER')
    )
    

Maybe you are looking for

  • Mini wake up monitor with Mail

    Embarrassing, even if unfortunately intermittent problem with my Mac Mini, os 10.11.5. When moved to enjoy TV with the night lights, my Mini kicks periodically on the Dell Monitor to get a boring jet of light, which lasts about 10 minutes. This seems

  • Printer in Windows 7 software

    MY79AH5093 Microsoft Windows 7 Home Premium 64 Setup USB cable / HP Photosmart C6280 all-in-one printer installation http://h10025.www1.HP.com/ewfrf/wc/softwareDownloadIndex?softwareitem=MP-76043-1&LC=en&DLC=en&cc=us&... Download HP printer Here are

  • Simulate the presence of an instrument

    Hi all! I read the data of an instrument which is in the laboratory and where there is junt a version of the runtime of labview instaled. The instrument is a GPIB multiplexer interface that uses sustainable intensification of CROPS. To get informatio

  • All programs and missing data and the message left notebook 'where are my files' on the computer

    original title: I use win xp Prof my computer has been open 24 hours. today when I started using the pc I was shocked as al my applications and software loaded on the system is I use win xp Prof my computer has been open 24 hours. today when I starte

  • Dell PowerVault LTO4-120 running under Ubuntu or Mac OS?

    Hello people. We must change our Dell PowerVault LTO4-120 on a machine that could be a PC running Ubuntu or even a desktop apple computer running Mac os 10.4. The problem is, how would it be possible to get a driver that works? I know not how, but on