Pivot table in sql

Hello

I need to rotate the table in sql as below:

My table looks like this:

SQL > select * from test;

VALUE NAME
-------------------- ----------
A                             1
B                             2
C                             3
A                             4
C                             5

I want to create an output like

A, B AND C

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

1 2 3

4        5

Any idea on the same?

create table test (varchar2 (20) name, value);

Insert into test values ('A', 1);
Insert into test values ('B', 2);
Insert into test values('C',3);
Insert into test values ('A', 4);
Insert into test values('C',5);

commit;

Hello

Here's one way:

WITH got_r_num AS

(

SELECT name, value

ROW_NUMBER () (PARTITION BY NAME

Value of ORDER BY

) AS r_num

OF the test

)

SELECT a, b, c

OF got_r_num

PIVOT (MIN (value)

FOR name IN ('A' got one

'B' b

'C' c

)

)

ORDER BY r_num

;

To rotate, you want columns that indicate which rows and columns of the output matches every input line.  In this case, the name column indicates the column, but there is nothing that indicates to the line, then derive (i.e. r_num), in the subquery called got_r_num.

For more info on swivel in Oracle, please refer to the Forum: Re: 4. How can I convert rows to columns?

Tags: Database

Similar Questions

  • Pivot table result without aggregate function

    Hi all

    We have the following two tables:

    SQL > select * from class;

    CLASS_ID COURSES

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

    1          1

    2          1

    3          1

    2          2

    3          2

    5          2

    6 selected lines.

    SQL > select * of course.

    COURSE_ID

    ----------

    1

    2

    The customer needs the output in the following format:

    class class class class

    1                    1               2               3

    2                    2               3               5

    I considered using the operator pivot tables however they require the use of an aggregate function, but there is no aggregation only required in the result here - we demand that the output as would a PivotTable?

    Try this.

    WITH class(CLASS_ID,COURSE) AS)

    1.1 DOUBLE UNION ALL SELECT

    SELECT 2.1 DUAL UNION ALL

    SELECT 3.1 FROM DUAL UNION ALL

    SELECT 2.2 DUAL UNION ALL

    3.2 DUAL UNION ALL SELECT

    SELECT DOUBLE 5.2)

    SELECT * FROM)

    SELECT THE COURSE

    CLASS_ID,

    ROW_NUMBER () OVER(PARTITION BY COURSE ORDER BY COURSE) RN

    CLASS)

    PIVOT (MAX (CLASS_ID) for (RN) IN (1 as CLASS1, 2 AS CLASS2, CLASS3 AS 3));

    OUTPUT:

    CLASS CLASS1 CLASS2 CLASS3

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

    1          1          2          3

    2          2          3          5

  • How to make a table temporary sql

    Hello

    I would like to create a table temporary sql - «create table #tempTable...» »

    but I get the error

    Is it possible to do it with Labview DB connectivity toolkit?

    Thank you... Eran

    I know that you can create a stored procedure and run it since in LabVIEW.  And within the stored procedure, you can create temporary tables.  I like this method because you can easily change the SP code without recompiling your VI.  Hope this helps.

  • How to combine the 2 tables in sql server 2008?

    Tell me how to combine 2 tables in sql server. and give me an example, I am a beginner again.

    You can get a faster or better response if you ask one of the instances of SQL Server dedicated from Microsoft here:

    http://social.technet.microsoft.com/Forums/en-us/category/sqlserver .

    (I'm sorry, but I can't move this thread for you because the two forums are working on separate platforms)

  • How to write data in an existing database table in sql using table in lab mode

    I am trying to write the data to an existing table in sql databse.but I don't know how to get it done me .plz help

    The error text is clear: the data provided does not match the number of columns. Your insertion data have 3 columns, how is appointed in the control of columns?

    It would be easier if you attached the VI with orders paid at the current values as default value.

    /Y

  • XML data in the table using sql/plsql

    Hi experts,

    Could you please help with the following requirement. I have the tags xml (.xml on a server file) below. I need to access this file and read the XML and insert into the db table using sql and plsql. Is it possible with the cdata below? And there is a nested this table.

    Could someone please guide me if you have a sample code file and xml.

    <? XML version = "1.0" encoding = "UTF-8"? >

    < generation_date > <! [CDATA [17/11/2015]] > < / generation_date >

    < generated_by > <! [CDATA [Admin Admin]] > < / generated_by >

    < year > <! [CDATA [2015]] > < / year >

    < month > <! [CDATA [01]] > < / month >

    < author >

    < author > <! [CDATA [user author]] > < / author > < author_initial > <! [CDATA [user]] > < / author_firstname > < author_country > <! [CDATA [author]] > < / author_lastname >

    < author_email > <! [CDATA [[email protected]]] > < / author_email >

    < author_data_01 > <! [CDATA []] > < / author_data_01 >

    < author_data_02 > <! [CDATA []] > < / author_data_02 >

    < items >

    < article_item >

    < article_id > <! [CDATA [123456]] > < / article_id >

    < publication > <! [CDATA [Al Bayan]] > < / publication >

    < section > <! [CDATA [Local]] > < / section >

    < issue_date > <! [CDATA [11/11/2015]] > < / issue_date >

    < page > <! [CDATA [2]] > < / print this page >

    < article_title > <! [CDATA [title.]] > < / article_title > < number_of_words > <! [CDATA [165]] > < / number_of_words >

    < original_price > <! [CDATA [200]] > < / original_price >

    < original_price_currency > <! [CDATA [DEA]] > < / original_price_currency >

    < price > <! [CDATA [250]] > < / price >

    < price_currency > <! [CDATA [DEA]] > < / price_currency >

    < / article_item >

    < / articles >

    < total_amount > <! [CDATA [250]] > < / total_amount >

    < total_amount_currency > <! [CDATA [DEA]] > < / total_amount_currency >

    < / author >

    < / xml >

    Thanks in advance,

    Suman

    XMLTABLE using...

    SQL > ed
    A written file afiedt.buf

    1 with t (xml) as (select xmltype ('))
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    [[12 [email protected]]] >
    13
    14
    15
    16
    17
    18
    19


    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33 ") of the double)"
    34-

    35 end of sample data
    36-
    37 - assumptions:
    (38 - a) XML may have several tags
    (39 - b) each may contain more
    40-
    41 select x.gen_by, x.gen_date, x.mn, x.yr
    42, y.author, y.auth_fn, y.auth_ln, y.auth_cnt, y.auth_em, y.auth_d1, y.auth_d2

    43, z.id, z.pub, z.sec, z.iss_dt, z.pg, z.art_ttl, z.num_wrds, z.oprice, z.ocurr, z.price, z.curr
    44 t
    45, xmltable ('/ authxml')
    from $ 46 t.xml
    path of 47 columns gen_date varchar2 (10) '. / generation_date'
    48, path of varchar2 (15) of gen_by '. / generated_by'
    49, path of varchar2 (4) year '. "/ year"
    50 varchar2 (2) mn road '. "/ month"
    51, path of xmltype authors '.'
    52                 ) x
    53, xmltable ('/ authxml/authors ')
    from $ 54 x.authors
    author of 55 path of varchar2 columns (15) '. / author'
    56, path of varchar2 (10) of auth_fn '. / author_firstname'
    57, path of varchar2 (10) of auth_ln '. / author_lastname'
    58 road of VARCHAR2 (3) auth_cnt '. / author_country'
    59 road of varchar2 (20) of auth_em '. / author_email'
    60 road of varchar2 (5) of auth_d1 '. / author_data_01'
    61, path of varchar2 (5) of auth_d2 '. / author_data_02'
    62, path of xmltype articles '. / Articles'
    63                 ) y
    64, xmltable ('/ Articles/article_item ')
    from $ 65 y.articles
    path id 66 number columns '. / article_id'
    67, path of varchar2 (10) pub '. ' / publication.
    68 road of varchar2 (10) dry '. / section'
    69, path of varchar2 (10) of iss_dt '. / issue_date'
    70 road of VARCHAR2 (3) pg '. "/ print this page"
    71, path of varchar2 (20) of art_ttl '. / article_title'
    72, path of varchar2 (5) of num_wrds '. / number_of_words'
    73, path of varchar2 (5) of oprice '. / original_price'
    74 road to VARCHAR2 (3) ocurr '. / original_price_currency'
    75, path of varchar2 (5) price '. "/ price"
    76, path of VARCHAR2 (3) curr '. / price_currency'
    77*                ) z
    SQL > /.

    GEN_DATE GEN_BY YEAR MN AUTHOR AUTH_FN AUTH_LN AUT AUTH_EM AUTH_ AUTH_ ID PUB DRY ISS_DT PG ART_TTL NUM_W OPRIC HEARTS PRICE OCU
    ---------- --------------- ---- -- --------------- ---------- ---------- --- -------------------- ----- ----- ---------- ---------- ---------- ---------- --- -------------------- ----- ----- --- ----- ---
    17/11/2015 Admin Admin 2015 01 user author user author [email protected] 123456 UAE Al Bayan Local 11/11/2015 2 is the title.   165 200 AED AED 250

    Of course, you'll want to change the types of data, etc. as needed.

    I assumed that the XML can contain several "" sections and that each section can contain several entries.

    Thus the XMLTABLE aliasing as 'x' gives information of XML, and supplies the data associated with the XMLTABLE with alias 'y' which gets the multiple authors, which itself section of the XMLTABLE with alias 'z' for each of the article_item.

    CDATA stuff are handled automatically by SQLX (XML functionality integrated into Oracle's SQL)

  • Pivot table column alignment

    Hi all

    I use the Oracle 11 g database to develop my application.

    I've created a generic column report.

    For this I used the concept of PIVOT table.

    My example query is

    with pivot_data like)

    SELECT DEPTNO, JOB, SAL, BISHOP

    WCP

    )

    SELECT *.

    OF pivot_data

    PIVOT)

    SUM (SAL)

    FOR DEPTNO

    IN (& P90009000_LIST.)

    )

    This output is

    WORK BISHOP 10 20 30

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

    PRESIDENT 5000

    7902 800 CLERK

    7698 950 CLERK

    7788 1100 CLERK

    7782 1300 CLERK

    7698 5600 SELLER

    MANAGER 7839 2450 2975 2850

    7566 6000 ANALYST

    8 selected lines.

    but I need the output as below

    BISHOP OF WORK 10 20 30

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

    PRESIDENT 5000

    THE 800 7902 CLERK

    THE 950 7698 CLERK

    1100 7788 CLERK

    1300 7782 CLERK

    5600 7698 SELLER

    MANAGER OF 2450 2975 2850 7839

    6000 7566 ANALYST

    8 selected lines.

    Come 10,20,30 pivot columns

    How to do this in my application?

    Thank you

    Su.GI

    Thanks Solomon.

    I used the code below.

    His job very well.

    with pivot_data like)

    SELECT DEPTNO, JOB, SAL, & P90009000_LIST., BISHOP

    WCP

    )

    SELECT *.

    OF pivot_data

    PIVOT)

    SUM (SAL)

    FOR DEPTNO

    IN (& P90009000_LIST.)

    )

    Thank you

    Su.GI

  • For Timo: Dynamically create pivot table binding

    Hi Timo,

    Long time ago you have this announcement on a thread:

    "The solution for your use a 2013 DOAG case, I presented was to create binding table pivot out user defined attributes in the table."

    For the defined attributes, VO is created dynamically and the pivot link.

    The pivot link is exchanged during execution as well as the activation of the adequate VO Dynamics to get only the

    necessary data for the pivot table in particular.

    ......

    I can't give you a working example because it is too complex. I can make available slides, but they are in German. "

    We have the same problem.

    Can you please send me this presentation on: email address removed by the moderator - there is no private through this public forum consultation >

    I can't find this Presentation on the Internet.

    Maybe, if you have some examples of simple work, too.

    Kind regards

    Diana

    Diana, you can get the DOAG2013_DynamicPivotTable_virtual7 blades | JDev & ADF Goodies

    The sample is too complex to be made available through my blog.

    Timo

  • Sort data in pivot table

    Hi Experts,

    Here's the requirement I need to sort the text Text_field field say to sort this column, I called another field. Sort_Text_field.

    I have the pivot table as follows

    Can I sort Text_field even if Sort_Text_field is not in the PivotTable on the side.

    Thank you!

    Month1-(Jan) Month2-(Feb)
    Text_fieldMetricValue1MetricValue2


    Thank you!!

    Just in case if helps others. Tim Dexter tanks

    Follow this link: https://blogs.oracle.com/xmlpublisher/entry/new_skool_crosstabbing

    Customization

    One new feature that I discovered this week is the ability to show a single column and sort by another. I got a data set which was extracting the month abbreviations, we wanted to show for months through the top and headers of lines on the side. As you know XSL is not very good with dates, in particular recognizing the names of months. He just wants to sort them alphabetically, so, after comes before Jan, etc..
    A way around this is to generate a number of months to the sides of the month and which allows to sort. We can do that in the crosstab, unfortunately it is not exposed in the user interface still but its doable.

    Go back and take a look at the initial crosstab command. especially the line inputs and columns. There, you will find the sort criteria.

    "ProductsBrand {, o = a, t = t}, PeriodYear {, o = a, t = t}.

    Note these key commas inside the braces? Because there is no field that precedes them, this means that the crosstab should sort on the column before the brace that is PeriodYear. But you can insert another column in the data set to be sorted. For myself how I needed to work.

    <>" _Fund_Type_._Fund_Type_Sort_, o = a, t = n} ';' _Fiscal_Period__Amount__._Amt_Fm_Disp_Abbr_ {_Fiscal_Period__Amount__._Amt_Fiscal_Month_Sort_, o = a, t = n} ';' _Execution_Facts_._Amt_ ';' amount '? >

    Excuse the horribly verbose XML tags, good ol' BIEE: 0) emboldened columns are not in the table, but in the data set. I just open the field, dropped and changed the value type (t) is 'n', number, instead of the default 'a' and my crosstab started sorting how I wanted that it.

    If you find other tips and tricks, please share in the comments.

  • Remove sorting in a Pivot table view

    Hi people,

    How to remove the column header sort options in the pivot table view?

    Thank you

    AJ

    You want to remove the small arrows on the column header in a pivot view?

    If so, the options are available in the analysis criteria tab. The problem is it cannot be set to a point of view, they perform the whole analysis

    In the criteria-> Properties tab right next to the filters and the stages of selection analysis-> Interactions tab.

    Mark, if this can help

  • How to get the QDR of ADF Pivot table datacell

    JDeveloper 11.1.1.5 version
    Java 1.6
    The ADF faces

    I want to click commandlink in a data cell that sends the value of the header cells to a bean of support. I think that we must get the QDR of a clicked data cell, but how?

    I created the PivotTable: column headers consist of a variable number of dates; row headers consist of the names of the units. The data that cross are a percentage of variance using energy over time. (There is no calculation in the PivotTable, just displaying data from the view).

    ........ 11 Jan 12 13 Jan Jan jan 14. .etc
    Module-1 2.00 5, 25 - 9.30-11.15
    Unit-2 - 554.22 497.00 7.70 2.00
    Unit-3 10.00 - 5, 00 5.00 1.00

    To the cell above it with 497.00 value, the user must click this value (commandlink) and the bean 1) calculate the values of the unit and the date to use as parameter values for ExecuteWithParams under another iterator and 2) navigate to another page using this another iterator.

    It seems that the QDR (reference data) is involved, but can't find enough information about how to implement the same.

    Here are the PivotTable on the jspx:

    < dvt:pivotTable id = "pivotTable1".
    Summary = "reading analytical pivot table.
    value = "#{bindings." CdsaReadingsItfVwView1.pivotTableModel}.
    var = 'cellData.
    varStatus = "cellStatus" >
    < dvt:dataCell >
    < af:commandLink id = "cl".
    Text = "#{cellData.DataValue} '"
    action = "#{pivot_bean.commandlink_action}" / >
    < / dvt:dataCell >
    < / dvt:pivotTable >



    In the bean, we try to getPivotTable(), but it is always null.

    Any direction is welcome.

    David K

    Check how the PivotTable selection demo was created:
    http://jdevadf.Oracle.com/ADF-richclient-demo/faces/feature/PivotTable/pivotTableSelection.JSPX
    Code for this demo here:
    http://www.Oracle.com/technetwork/developer-tools/ADF/documentation/ADF-faces-RC-demo-083799.html

  • Pivot Table guest issue

    Hello

    I can place the Pivot Table guest column does not display values section in the menu drop-down showing only a single value.

    Version is 11.1.1.6.4 OBIEE and Mozilla Firefox 19.0.2

    How to overcome this problem.

    THX,

    If the column contains more than 1 value then browser. Check in IE or Chrome.

  • Exclude a measure the total general dynamic level 'Lines' of a pivot table

    Experts,

    Is it possible to exclude a measure the total general dynamic level 'Lines' for a pivot table?

    Version - OBIEE 10g

    Kind regards
    LIBERATOR

    No, I mean not the dropdown list above when you edit the formula in the column. It of there on 11g but don't remember off the top of my head if it is in the same place on 10g.

    Paul

  • Problem loading table in SQL server

    Hello

    I'm trying to load a table in SQL server from another instance of SQL server.

    I defined the physical and and stores of data, logical and reverse engineered models to retrieve tables.

    The target table has been created manually...

    If I try to launch the interface I get the fololowing error


    ODI-1227: SrcSet0 (load) task fails on the source of connection MICROSOFT_SQL_SERVER data WAREHOUSE.
    Caused by: java.sql.SQLException: incorrect syntax [FMWGEN] [SQLServer JDBC Driver] [SQL Server] about ' < '.
    at weblogic.jdbc.sqlserverbase.ddb_.b (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddb_.a (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddb9.b (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddb9.a (unknown Source)
    at weblogic.jdbc.sqlserver.tds.ddr.v (unknown Source)
    at weblogic.jdbc.sqlserver.tds.ddr.a (unknown Source)
    at weblogic.jdbc.sqlserver.tds.ddq.a (unknown Source)
    at weblogic.jdbc.sqlserver.tds.ddr.a (unknown Source)
    at weblogic.jdbc.sqlserver.ddj.m (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddel.e (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddel.a (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddde.a (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddel.v (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddel.r (unknown Source)
    at weblogic.jdbc.sqlserverbase.ddde.execute (unknown Source)
    at oracle.odi.runtime.agent.execution.sql.SQLCommand.execute(SQLCommand.java:163)
    at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:102)
    at oracle.odi.runtime.agent.execution.sql.SQLExecutor.execute(SQLExecutor.java:1)
    at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2913)
    at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2625)
    at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:558)
    at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:464)
    at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2093)
    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ 2.doAction(StartSessRequestProcessor.java:366)
    at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
    at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:300)
    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$ 0 (StartSessRequestProcessor.java:292)
    to oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$ StartSessTask.doExecute (StartSessRequestProcessor.java:855)
    at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)
    to oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$ 2.run(DefaultAgentTaskExecutor.java:82)
    at java.lang.Thread.run(Thread.java:662)

    He tries to run the following SQl and I don't know why she strives to drop and create a view in the source system? The interface that I do turn above has only one source of target mapping...

    Delete the < Undefined > view. SQLDATAWH_DATAWAREHOUSEAccountDim

    Indications will be useful...

    Thanks in advance...

    Whirlpool says:
    Can you please let me know the name of the lkm and ikm which must be selected for SQL SERVER to SQL SERVER.

    You can see this
    http://docs.Oracle.com/CD/E23943_01/integrate.1111/e12644/ms_sqlserver.htm#BGBJBGCC

  • How can I customize the font size for Pivot Table Section 11 g?

    Hi all

    I'm new to CSS customization, and I followed the suggestions to use tools like Firebug to look at the CSS styles applied to a particular item.

    11 g, I have a report that uses rotating sections of the table to display the numbers associated with the Department in each Department and the sections. Using Firebug, I see that the titles of the Department are on police-size: 9px; by default. The HTML is:

    < class = "PTSC OOLT" td style = "" are-size: 9px; ">"

    I would like to change the font size default to the values of the Section of the Pivot Table so that it displays 11px-size of font instead of 9px for all reports.

    Digging around, I don't see a way to do unless I have use custom styles custom.css and reference in each of my pivot views. Does anyone else have a suggestion how how I can change the default font size without having to create a custom.css entry? We have many existing reports that have been migrated over 10 g that I prefer not to go back and must add a reference to each view simple pivot.

    Thank you.

    Hello

    Please see:
    http://www.Oracle.com/WebFolder/technetwork/tutorials/OBE/FMW/bi/bi1113/customizing_obiee11g/customizing_obiee11g.htm
    and search for "Deployment of a Style Custom"

    Concerning
    Young

Maybe you are looking for

  • Update iOS 9.3.3 error on my iPad Air

    I am able to download this update without problem. However, I get a failure to check the update error. This happens only on my iPad Air. I've updated on two models of iPhone 5 s and a mini iPad. Any ideas? Any suggestion? I deleted and reloaded the s

  • Motorcycle Tieline

    I received what looks like a very short time (about 10cm) extension cable for helmet labelled "Bike TIELINE 85014326001" with my phone. It's to short to be of any value in it as an extension - so what?

  • I bought a game and when I download on my new Ipad it says I have to buy it again. Please help if you can

    I bought a game some time ago and now I have a new Ipad when I download the game for my new I pad, this says that I have to buy it again. How can some tell me please

  • Appears that I have 2 desktops, one being for some time ago and inaccessible

    Hello I had this problem in the past, but I don't remember how I (or someone else) fixed it the last time.  Here's my situation: currently I have what appears to be a desktop computer of some time ago (there the icons/games, I used to play / remember

  • issues related to the parameter in the procedure

    Hi allI have a procedure which the code is given below:create or replace PROCEDURE seods01.get_cert_tx_lot_tmp (acct_alt_id_in in VARCHAR2, acct_alt_id_cntx_cde_in IN VARCHAR2 default 'COLA account number.,