PivotChart


Hi Experts,

I'm doing the dynamic pivot query. I know how to convert a query to rotate. But I'm just wondering can I rotate.

For example.

A classic pivot:

> > select * from sec_q;

the column names are respectively:

Reffacture invoice_amount invoice_row_num

01032925 1 196,28

01048083 1 152,57

01048083 2 98,87

01053119 1 188,5

01070391 1 358,84

01078898 1 165,78

01081126 157,57 1

01085899 1 87,19

01085899 2 1.31

01085899 3 164,82

However, I do not know the invoice_row_num max value because it can reduce the dynamic

I want the following output

AccountNum invoice_num_1 invoice_num_2 invoice_num_3...  invoice_num_max

01085899 1.31 87,19 164,82 0

01081126                157,57                     0                         0                       0

As far as I know what follows does not meet my expectations

SELECT * from sec_q

Pivot

(max (invoiceamount) to (no_lig) in ('1 ', '2', '3', '4', ' 5' * BECAUSE THIS VALUE CHANGES DYNAMICS * ));

For example, suppose that my table as below

sec_q

(

accountnumnumber,

number of invoice_amount

number of invoice_row_num

)

each accountnum do not dublicate, and all the invoice_amoun transposed and column headers must be invoice_row value

Is this possible?

Thanks in advance

Hello

See also

Re: County report and the sum of the number of rows by multiple columns

https://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4471013000346257238

How to arrange the result of the query and adding column outomatic translate

Tags: Database

Similar Questions

  • Setting of the names of columns in the query in PivotChart

    Hi all

    I have columns for the wrong parameter names in a PivotChart query and I was wondering if someone could help me please understand me what I need to do.

    Help me help you, I have set up an example scenario in my hosted account. Here's the info to connect to my site hosted at [http://apex.oracle.com]
    Workspace: MYHOSTACCT
    Username : DEVUSER1
    Password : MYDEVACCT
    And here's my test request info:
    ID     : 42804
    Name   : dynamic query test
    Page   : 1
    Table 1: PROJECT_LIST         (Alias = PL...  Listing of Projects)
    Table 2: FISCAL_YEAR          (Alias = FY...  Lookup table for Fiscal Years)
    Table 3: PROJECT_FY           (Alias = PF...  Intersection table containing project fiscal years)
    Table 4: PROJECT_FY_HEADCOUNT (Alias = PFH... Intersection table containing headcount per project and fiscal year)
    Please forgive the excessive for this example standardization, as I wanted to keep the table structure similar to my actual application, that has a lot more going on.

    In my example, I have in the region to "Select the criteria", where the user specifies the project and the range of exercise that he or she would like to report. Click on the search button, and the report refers staff of revolving project for the range of the financial year.

    I've got it works using a query hardcoded, which is displayed in the region of the "hard-coded query." In this query, I have basically come back every year and to lay down the conditions on each column that determines if this column should be displayed or not according to the selected user. While this works, it is not ideal, because there could be several years more to take into account, and is not very dynamic. Any time an exercise is added to the table of FISCAL_YEAR, I update this page.

    So, after reading all the forums pivot OTN SQL and thread pivot "ask Tom", I was able to create a second region labeled "Dynamic motion" in which I created a dynamic query to return the same results. It of a much more intuitive solution and works very well; However, the column names are generic in the report.

    I had to put the query to analyze at runtime, because the list of column selection is dynamic, which violates the rules of SQL. Can someone help me please how can I specify my column names in the area of dynamic query to get the values of column even I receive in the region of hardcoded to understand?

    Please let me know if you need more information and thanks a lot in advance!

    Mark

    Take a look at your request now. I added a function in your workspace, change the headers to be pl/sql base, added an element hidden to contain the query you create and pass in the service to get your item headers...

    Thank you

    Tony Miller
    Webster, TX

    On the road of life... He has "windshield", and there are "bugs".
    (splat!)
    "Squeegees wanted."

    If you answer this question, please mark the thread as closed and give points where won...

  • What is b & w differenence table & table PivotChart?

    Hai...
    What is b & w differenence table & table PivotChart?

    Hello

    PivotTable

    http://en.Wikipedia.org/wiki/Pivot_table

    table view

    IT has normal view showing all columns similar to the database

    where, as in table view you ll some additional features like

    Sort order, of the green bar

    Thank you
    saichand.v

  • Table PivotChart OBIEE 11 g format

    Hi all

    I have a requirement where I need to change the background color of the cells in dash (cell more Virgin at the top left) and below white color.
    I am able to convert the background color of cell dash in white by call Java script

    < script type = "text/javascript" >
    TDS var = document.getElementsByTagName ('td');
    var LCSS = new Array();
    for (td var = 0; td < tds.length; td ++) {}
    If (tds [td] .className! = 'CFC') {}
    continue;
    }
    TDS [td].style.backgroundColor = "#FFFFFF";
    TDS [td].style.borderLeft = "#FFFFFF";
    TDS [td].style.borderTop = "#FFFFFF";
    lCSS.push (tds [td] .innerHTML);
    }
    for (var len = 0; len < lCSS.length; len ++) {}
    }
    < /script >

    but I am unable to change the background color of the cell below (which is also empty).

    Can someone please suggest me how I can change the color for this?

    Thank you.

    Please mark it as correct, it would be grate. !!!

  • I'm having issues by rotating the following data... help please...

    So the following question:

    SELECT YEARS_,METRIC_NAME,METRIC_VALUE from (
      (SELECT to_char(ADD_MONTHS(SYSDATE,((-ROWNUM+1)*12)),'YYYY') YEARS_ from DUAL CONNECT BY LEVEL<=5)
      LEFT JOIN CORE_METRICS on YEARS_=CORE_METRICS.METRIC_SUBNAME
      and CORE_METRICS.METRIC_VALUE IS NOT NULL)
    
    
    

    SPOKEMETRIC_NAMEMETRIC_VALUE
    2013BACKUP_TB_COST100
    2014BACKUP_TB_COST200
    2013VMAX_TIER1_TB_COST150
    2014VMAX_TIER1_TB_COST300

    What I would do, it's this array of PivotChart so that the METRIC_NAMES are the columns and values are the METRIC VALUE

    and each row in the returned table would be one spoke...

    So, something like

    YEARS BACKUP_TB_COST VMAX_TIER1_TB_COST
    2013100150
    2014200300

    I want to display. I don't know because I'm on 11g can I somehow turn the table around, or do I have to write a PLSQL procedure to cope with this.

    Thank you

    Rob

    Hello

    bostonmacosx wrote:

    with pivot_data as (SELECT spoke, METRIC_NAME, METRIC_VALUE of)

    (SELECT to_char (ADD_MONTHS (SYSDATE, ((-ROWNUM+1) * 12)), 'YYYY') spoke of DOUBLE CONNECT BY LEVEL)<>

    LEFT JOIN CORE_METRICS on spoke = CORE_METRICS. METRIC_SUBNAME

    and CORE_METRICS. METRIC_VALUE IS NOT NULL))

    SELECT spoke, METRIC_NAME, pivot_data METRIC_VALUE

    pivot)

    SUM (METRIC_VALUE)

    for METRIC_NAME

    IN (NETAPP_TB_COST,

    MAINFRAME_COST_PER_CPU,

    VMAX_TIER1_TB_COST,

    VNX5500_TB_COST,

    RS6000_COST_PER_CPU,

    SERVER_COST_PER_CPU,

    BACKUP_TB_COST,

    VMAX_TIER2_TB_COST)

    );

    In the PIVOT clause, use single quotes around names:

    pivot)

    SUM (METRIC_VALUE)

    for METRIC_NAME

    IN ('NETAPP_TB_COST',

    "MAINFRAME_COST_PER_CPU,"

    "VMAX_TIER1_TB_COST,"

    ...

    "NETAPP_TB_COST" (inside the single quotation marks) is a constant string 14

    NETAPP_TB_COST (outside the quotes) indicates a column or a function with the same name of 14 characters.  You get an error message on any such column existing if you do not have another error, to use a column name where a constant is expected, first of all.

    Of course, I can't test anything, until you post the data.

  • How to arrange the result of the query and adding column outomatic translate


    Hello

    my need to find number of devices activated per day in the city, my data as below

    1City_2Samsung
    5City_2IPhone
    4City_2IPhone
    2City_2IPhone
    1City_2IPhone
    1Ville1Samsung
    3Ville1Samsung
    17Ville1IPhone
    12Ville1IPhone
    5Ville1IPhone
    3Ville1IPhone
    3Ville1IPhone
    6Ville1IPhone
    7Ville1IPhone
    1Ville1IPhone
    3City_3IPhone

    I need the result to be as below but not only (IPhone and Samsung) device name could be any new device like HTC or compressed, then is it possible to add a new type of device automatically in a column, once a new device type show up in devices activated daily,

    CityTotal enabled accountsIPhoneSamsung
    Ville158544
    City_213121
    City_3330

    my table as below,

    Create table test values (number count1, city varchar2 (10), device)
    VARCHAR2 (10));

    Insert into test values (COUNT1, CITY, DEVICE)
    (17, 'Ville1', 'IPhone');

    Insert into test values (COUNT1, CITY, DEVICE)
    (1, "Ville1", "IPhone");

    Insert into test values (COUNT1, CITY, DEVICE)
    (7, "Ville1", "IPhone");

    Insert into test values (COUNT1, CITY, DEVICE)
    (6, 'Ville1', 'Phone');

    Insert into test values (COUNT1, CITY, DEVICE)
    (3, 'Ville1', 'IPhone');

    Insert into test values (COUNT1, CITY, DEVICE)
    (3, 'Ville1', 'IPhone');

    Insert into test (COUNT1, CITY, DEVICE) values (1, 'city' 1, 'Samsung');

    Insert into test values (COUNT1, CITY, DEVICE)
    (3, 'Ville1', 'Samsung');

    Insert into test values (COUNT1, CITY, DEVICE)
    (12, "Ville1", "IPhone");

    Insert into test values (COUNT1, CITY, DEVICE)
    (5, "Ville1", "IPhone");

    Insert into test values (COUNT1, CITY, DEVICE)
    (1, "City_2", "IPhone");

    Insert into test values (COUNT1, CITY, DEVICE)
    (2, 'City_2', 'IPhone');

    Insert into test values (COUNT1, CITY, DEVICE)
    (4, 'Ville_2', 'IPhone');

    Insert into test values (COUNT1, CITY, DEVICE)
    (5, "Ville_2", "IPhone");

    Insert into test values (COUNT1, CITY, DEVICE)
    (1, "City_2", "Samsung");

    Insert into test values (COUNT1, CITY, DEVICE)
    (3, 'City_3', 'IPhone');

    Thank you



    Hello

    Here's a way to use the solution to askTom ( ask Tom & quot; PivotChart & quot; )  in your case:

    CREATE OR REPLACE PROCEDURE dynamic_device_pivot
    (p_cursor ON SYS_REFCURSOR
    )
    AS
    l_query VARCHAR2 (30000): = "CHOOSE the city, SUM (count1) AS total_accounts;
    BEGIN
    FOR (IN) r
    SEPARATE device select
    OF the test
    ORDER BY device
    )
    LOOP
    l_query: = l_query | REPLACE (", SUM (DECODE (device," $X$ ", count1, 0)) as $X$")
    , '$X$'
    dbms_assert.simple_sql_name (r.device)
    );
    END LOOP;

    l_query: = l_query | 'FROM test GROUP BY city ORDER BY city';
    dbms_output.put_line (l_query |) "= l_query in dynamic_device_pivot");   -For debugging only

    P_cursor OPEN FOR l_query;
    END dynamic_device_pivot;
    /
    DISPLAY ERRORS

    RC VARIABLE REFCURSOR
    EXEC dynamic_device_pivot (: rc);

    PRINTING: rc

    The output is not quite what you have posted, due to a typing error, probably:

    CITY TOTAL_ACCOUNTS IPHONE SAMSUNG PHONE

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

    City1                  58         48          6          4

    City_2                 13         12          0          1

    City_3                  3          3          0          0

  • Turn the line in column

    Hi all

    Select * from t_temp;

    col1 col2 col3

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

    100a 1

    101 b 2

    103 c 3

    Output sought,

    a           b         c

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

    1           2          3

    Kind regards

    Fame

    SQL > create or replace procedure my_pivot (p_cursor in the sys_refcursor

    2)

    3 as

    long 4 l_query: = "select";

    5 I have COMP: = 0;

    6 start

    7 x in (select c2

    8 of t_temp

    9             )

    10 loop

    11 i: = i + 1;

    12 if i = 1

    13. can

    14 l_query: = l_query | Replace (q': max (decode(c2,'$X$',c3)) $X$ |', ' $X$ ')

    15, dbms_assert.simple_sql_name (x.c2)

    16                                    );

    17 other

    18 l_query: = l_query | Replace (q'|, max (decode(c2,'$X$',c3)) $X$ |', ' $X$ ')

    19, dbms_assert.simple_sql_name (x.c2)

    20                                    );

    21 end if;

    22 end loop;

    23-

    24 l_query: = l_query | 'from t_temp order by c1;

    25-

    26 dbms_output.put_line (l_query);

    27 open p_cursor for l_query;

    28-

    29 end;

    30.

    Created procedure.

    SQL > var refcursor rc

    SQL > define autoprint on

    SQL > exec my_pivot(:rc);

    Select max (decode(c2,'a',c3)) a, max (decode ('b', c2, c3)) b, max (decode(c2,'c',c3)) from t_temp by c1 c

    PL/SQL procedure successfully completed.

    A          B          C

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

    1          2          3

    1 selected line.

    Borrowed from the example of: ask Tom & quot; PivotChart & quot;

  • Using the annex to the budget

    I used the scheduling feature in history of program my function. Now, I want to make the significant schedule information with regard to the budget (that I created manually in a spreadsheet). For example, I want to know how many days a particular character is necessary so that I can add this number to the budget and know how the character will cost. I can go through the calendar and manually counting how many times each of the 63 characters in my script appear, but it seems that there must be an easier way for me to know for example, that the character of Mr. Clark is necessary for six days. Anyone?

    Ankita salvation,

    Thank you for your quick response. I generated the chart crossover of the character of the script, however, report that does not give me the information I need. The PivotChart report character tells me how many SCENES each character appears in the SCRIPT. But I need to know how many DAYS each character appears in the CALENDAR. I can then take this figure to the budget, it in and I know how much I pay for a type cast.

    Under the leadership of your suggestion, however, I searched more and perhaps discovered something useful for others trying to do the same. Generate a schedule and organize it. Then, from the view of planning, generate a PivotChart report Dates calendar. This report is broken down by character and day of shooting. I must still manually count the number of days that a character appears, but it is easy to scroll through the calendar and count manually.

    Thank you

    Daneeta

  • Help swivel... Please

    Hi all...

    Please help me with the following problem swivel.
    I went through some forums prior to this announcement and I just want to
    of course, what I do is correct.

    I need to rotate my "'per month'", like JAN_2012, FEB_2012.

    But my pivot "" in the paragraph"' is not static. I mean it's 'PivotChart.

    I mean, sometimes I'll have given 1 month and 2 months of time data etc etc...

    so everything I do is

    «"«DYNAMIC SQL»»»

    I'm generating my pivot "" in the paragraph"" depends on date settings I get.

    Here is the example of how I intend to use
    to build the "" pivot in the clause"" dynamically.

    It generates '' string' ' month and year dependent on the start date and end date.
    create or replace procedure test3(in_start_date date, in_end_date date) as
      v_query varchar2(4000);
    begin
      -- months string
      for crec in (select dte,
                          extract(year from dte) || '_' ||
                          upper(to_char(dte, 'Mon')) year_month
                     from (select add_months(in_start_date, level - 1) dte
                             from dual
                           connect by level <=
                                      ceil(months_between(in_end_date,
                                                          in_start_date)))) loop
        v_query := v_query || ' ' || '''' || crec.dte || '''' || ' ' ||
                   crec.year_month || ',';
      end loop;
      -- Years string
      for i in 1 .. floor(ceil(months_between(in_end_date, in_start_date)) / 12) loop
        v_query := v_query || ' ' || '''' ||
                   to_char(extract(year from in_start_date) + (i - 1)) || '''' || ' ' ||
                   to_char(extract(year from in_start_date) + (i - 1)) || ',';
      end loop;
      v_query := rtrim(v_query, ',');
      dbms_output.put_line(v_query);
    end test3;
    Please let me know if I'm doing something wrong or there at - it an easy way to
    Do it??

    (* I DON'T NEED THIS FEATURE in SQL, I CAN USE PL/SQL *)

    Hello

    Kumar wrote:
    ... Please let me know if I'm doing something wrong or there at - it an easy way to
    Do it??

    (* I DON'T NEED THIS FEATURE in SQL, I CAN USE PL/SQL *)

    The best way would be a dynamic slider, found in the site, AskTom

    If you want to build the part dyunamic of a PL/SQL PIVOT clause, this should give you some ideas:

    CREATE OR REPLACE FUNCTION     month_list
    (       in_start_date     DATE
    ,     in_end_date     DATE
    )
    RETURN     VARCHAR2
    DETERMINISTIC
    AS
        return_txt     VARCHAR2 (1000);
        this_month     DATE      := TRUNC (in_start_date, 'MONTH');
    BEGIN
        WHILE  this_month <= in_end_date
        LOOP
            return_txt := return_txt || Q'{, DATE '}'
                                     || TO_CHAR (this_month, 'YYYY-MM-DD')
                         || Q'{' }'
                         || TO_CHAR (this_month, 'YYYY_MON');
            this_month := ADD_MONTHS (this_month, 1);
        END LOOP;
    
        return_txt := LTRIM (return_txt, ', ');
    
        RETURN  return_txt;
    END     month_list;
    /
    

    You want to retrieve a value, so use a FUNCTION instead of a PROCEDURE.

    "... from DUAL CONNECT BY LEVEL<= ..."="" is="" handy="" a="" way="" of="" simulating="" a="" loop="" in="" pure="" sql,="" but="" pl/sql="" has="" real="" loops,="" so="" there's="" no="" need="" to="" simulate="">

    If you are rotating on a DATE, you can find it easier not to convert the DATE into a VARCHAR2. The above function compares the DATEs, not VARCHAR2s.
    In general, try to avoid the conversion from one type of data to another.

  • ExtractValue

    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for HPUX: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    /* Formatted on 4/5/2012 5:18:38 PM (QP5 v5.185.11230.41888) */
    DROP TABLE mytab;
    
    CREATE TABLE mytab
    (
       job_request_id         INTEGER,
       job_parameter_id_xml   XMLTYPE
    );
    
    SET DEFINE OFF;
    
    INSERT INTO mytab (JOB_REQUEST_ID, JOB_PARAMETER_ID_XML)
         VALUES (
                   858554,
                   XMLTYPE (
                      '<PivotSet><item><column name = "JOB_PARAMETER_ID">1000</column><column name = "VALUE_TX">208844</column></item><item><column name = "JOB_PARAMETER_ID">1001</column><column name = "VALUE_TX">165972</column></item><item><column name = "JOB_PARAMETER_ID">1007</column><column name = "VALUE_TX">3</column></item><item><column name = "JOB_PARAMETER_ID">1008</column><column name = "VALUE_TX">1580</column></item></PivotSet>'));
    
    INSERT INTO mytab (JOB_REQUEST_ID, JOB_PARAMETER_ID_XML)
         VALUES (
                   858555,
                   XMLTYPE (
                      '<PivotSet><item><column name = "JOB_PARAMETER_ID">1000</column><column name = "VALUE_TX">261015</column></item><item><column name = "JOB_PARAMETER_ID">1001</column><column name = "VALUE_TX">189185</column></item><item><column name = "JOB_PARAMETER_ID">1007</column><column name = "VALUE_TX">3</column></item><item><column name = "JOB_PARAMETER_ID">1008</column><column name = "VALUE_TX">25</column></item></PivotSet>'));
    
    COMMIT;
    expected results
     job_request_id    1000        1001           1007       1008
     858554             208844     165972        3            1580
     85855               261015     189185        3            25
    not very strong with the xml stuff, I read the documentation on certificate of value, but I couldn't make it work. any help is appreciated thank you.

    Hello

    A few comments:

    (1) forget the extractvalue() function, it is discouraged in your version. Oracle recommends using the XQuery XMLQuery() and XMLTable() functions now.

    (2) I see you try to work on the content provided by the operator PIVOT XML, but as always, unless you know the number of columns expected in advanceyou can have any output in relational format by using a simple SELECT statement. You can do this with ODCI but I don't think you want to go this way.

    So basically what follows, but it clearly defeated the purpose of using a PivotChart in the first place:

    SQL> select t.job_request_id, x.*
      2  from mytab t
      3     , xmltable(
      4         '/PivotSet'
      5         passing t.job_parameter_id_xml
      6         columns "1000" number path 'item[column[1]="1000"]/column[2]'
      7               , "1001" number path 'item[column[1]="1001"]/column[2]'
      8               , "1007" number path 'item[column[1]="1007"]/column[2]'
      9               , "1008" number path 'item[column[1]="1008"]/column[2]'
     10       ) x
     11  ;
    
                             JOB_REQUEST_ID       1000       1001       1007       1008
    --------------------------------------- ---------- ---------- ---------- ----------
                                     858554     208844     165972          3       1580
                                     858555     261015     189185          3         25
     
    

    If you are looking for a text output only, it's another story like this boils down to the aggregation of the chain, but once again this could be done more simply without resorting to format XML PIVOT.
    A quick attempt using an tab separator:

    SQL> select 'JOB_REQUEST_ID' || chr(9) ||
      2         xmlcast(
      3           xmlquery('let $sep := codepoints-to-string(9)
      4                     return string-join(/PivotSet/item/column[@name="JOB_PARAMETER_ID"], $sep)'
      5                    passing JOB_PARAMETER_ID_XML
      6                    returning content)
      7           as varchar2(4000)
      8         ) as report
      9  from mytab
     10  where rownum = 1
     11  union all
     12  select to_char(job_request_id) || chr(9) ||
     13         xmlcast(
     14           xmlquery('let $sep := codepoints-to-string(9)
     15                     return string-join(/PivotSet/item/column[@name="VALUE_TX"], $sep)'
     16                    passing JOB_PARAMETER_ID_XML
     17                    returning content)
     18           as varchar2(4000)
     19         )
     20  from mytab
     21  ;
    
    REPORT
    --------------------------------------------------------------------------------
    JOB_REQUEST_ID     1000     1001     1007     1008
    858554     208844     165972     3     1580
    858555     261015     189185     3     25
     
    
  • piviot table

    I have a request of OBIEE dashboard that has 7 PivotTables and according to the days of the week, we automatically default to a specific PivotTable. Is it possible to OBIEE dynamically by default for a table of specific PivotChart based on a condition?
    (1) all data are same
    (2) if the data are different is different way to go.

    Thanks and greetings
    Pallis

    Published by: pallis may 2, 2011 09:20

    I assumed that the seven reports are different, the case more "difficult". If the columns are identical, it is easy to change what I'm going to tell you it would be much simpler.

    (1) create the seven reports to what you want to display.

    (2) add an additional column to each report.

    (3) in all seven reports, enter this in the window of the column 'extra ': fx

    DAYOFWEEK (CURRENT_DATE)

    In default OBIEE, function DAY WEEK will return the following text:

    Sunday = 1
    Monday = 2
    Tuesday = 3
    Wednesday = 4
    Thursday = 5
    Friday = 6
    Saturday = 7

    (4) in the first report, add a filter for the column 'extra' as follows: ' equal to / is in "1

    This report returns only records when is 'today' Sunday.

    (5) add a filter to each of the other 6 reports change the report to each day of the week.

    (6) add each report to its own Section in the dashboard.

    (7) for each Section, click Section > properties > guided Navigation.

    (8) find the same report as in the Section and then check the radio button "If the report returns lines."

    Now automatically, as a report shows based on what day of the week it is.

  • Summary query

    Sorry for the vague subject line, but I don't know what to call it.

    First of all, here is my version info:
    Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - production
    PL/SQL Release 10.1.0.4.0 - Production
    "CORE 10.1.0.4.0 Production."
    AMT for 32-bit Windows: Version 10.1.0.4.0 - Production
    NLSRTL Version 10.1.0.4.0 - Production

    I'm trying to summarize some data, similar to a table of PivotChart from excel. Here is an example
    CREATE
      TABLE "SKIP"."PRETZELS"
      (
        "ID"          NUMBER NOT NULL ENABLE,
        "NAME"        VARCHAR2(20 BYTE),
        "COUNTRY"     VARCHAR2(20 BYTE),
        "CONSUMPTION" NUMBER,
        CONSTRAINT "PRETZELS_PK" PRIMARY KEY ("ID") USING INDEX PCTFREE 10 INITRANS
        2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS
        2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
        TABLESPACE "USERS" ENABLE
      )
      PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
      (
        INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
        FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
      )
      TABLESPACE "USERS" ;
    
    INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('1', 'Classic Twist', 'US', '1000')
    INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('2', 'Classic Twist', 'Brazil', '3030')
    INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('3', 'Stick', 'US', '880')
    INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('4', 'Stick', 'Germany', '190')
    INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('5', 'Stick', 'Canada', '400')
    INSERT INTO "SKIP"."PRETZELS" (ID, NAME, COUNTRY, CONSUMPTION) VALUES ('6', 'Soft', 'Germany', '4000')
    And if I run the present:
    SELECT  
         p.name AS "NAME",
         MAX (CASE WHEN p.country = 'US'   THEN 'YES' ELSE 'NO' END)     AS US, 
         MAX (CASE WHEN p.country = 'Brazil'   THEN 'YES' ELSE 'NO' END)     AS BRAZIL, 
         MAX (CASE WHEN p.country = 'Germany'   THEN 'YES' ELSE 'NO' END)     AS GERMANY,
         MAX (CASE WHEN p.country = 'Canada'   THEN 'YES' ELSE 'NO' END)     AS CANADA
    --
    FROM skip.pretzels p
    --
    WHERE 
         p.country IN ('US', 'Brazil', 'Germany', 'Canada') 
    --
    GROUP BY p.name
    I get this (points added) to maintain the alignment of the column:
    NAME............US....BRAZIL..GERMANY..CANADA
    Soft............NO....NO......YES......NO
    Stick...........YES...NO......YES......YES
    Classic Twist...YES...YES.....NO.......NO
    What I want to do is to replace the 'YES' to consumption. In other words
    NAME............US....BRAZIL..GERMANY..CANADA
    Soft............NO....NO......4000.....NO
    Stick...........880...NO......880......400
    Classic Twist...1000..3030....NO.......NO
    It seems that it would be a kind of a compound SQL statement? Like replace the 'YES' with something like SELECT p.country WHERE p.consumption = 'US' and p.name =?

    Of course my real data are not a database of pretzel, but this should be a good analog. Moreover, my real data have a dozen 'country' and two thousand "names."

    In fact, just in case eponymous, combination of country can appear several times:

    SELECT
     p.name AS "NAME",
     NVL(TO_CHAR(SUM(CASE WHEN p.country = 'US'   THEN CONSUMPTION END)),'NO') AS US,
     NVL(TO_CHAR(SUM(CASE WHEN p.country = 'Brazil'   THEN CONSUMPTION END)),'NO') AS BRAZIL,
     NVL(TO_CHAR(SUM(CASE WHEN p.country = 'Germany'   THEN CONSUMPTION END)),'NO') AS GERMANY,
     NVL(TO_CHAR(SUM(CASE WHEN p.country = 'Canada'   THEN CONSUMPTION END)),'NO') AS CANADA
    --
    FROM pretzels p
    --
    WHERE
     p.country IN ('US', 'Brazil', 'Germany', 'Canada')
    --
    GROUP BY p.name
    /
    
    NAME                 US         BRAZIL     GERMANY    CANADA
    -------------------- ---------- ---------- ---------- ----------
    Soft                 NO         NO         4000       NO
    Stick                880        NO         190        400
    Classic Twist        1000       3030       NO         NO
    
    3 rows selected.
    
    SQL> 
    

    SY.

  • Keep the drill parent values

    We have a geographical hierarchy
    Contains AREA->-> country-> parts-> city.

    If the user belongs to ASIA PAC report begins to ASIA PAC.
    When the user explores ASIA PAC, he sees the child nodes of ASIA PAC, i.e. 3 areas - ANZ_AREA, ASIA_AREA, INDIA_AREA.
    When the user explores ANZ_AREA, he sees the child nodes of the ANZ NEIGHBORHOOD. But the INDIA_AREA ASIA_AREA AND disappear.
    The user wants to see also, parent nodes when he explores. He won't make them disappear.

    Please let me know how to achieve this.

    Yes, PivotChart, you create reports for each level.

  • Pivot of the Oracle

    I want to know if there is a better way to run this query.

    The current table layout
    group          division           class           stage          endage          rate
    
    Go               001                01              0               19               .4
    Go               001                01             20              24               .5
    G0               001                01             25              29               .6 
    G0               001                01             30              34               .2
    Required output
     
    group   division    class     a1    ae1     rt1    a2    ae2     rate2    a3    ae3    rt3    a4  ae4  rt4           
    Go        001         01      0      19      .4     20     24       .5       25     29     .6    30   34   .2
    I'm trying to do this using a function passing rownum, class, division, group as parameters. Performance is not bad.


    I was wondering if there was any other way to do it too.

    I use Oracle 10.2

    Thanks in advance

    Hello

    Bob wrote:
    ... This is the example you want me to try? ...

    Yes, something like that. As I've mentioned before, you'll want to MIN or MAX instead of COUNT.

    If so could you please link to my table. I guess I won't be able to do this way. I have to use PivotChart. because I will not know the rates to hardcode.

    Rates matter? Judging by the function you have posted, it resembled "ROW_NUMBER"... ORDER BY low_age"was the crucial thing, which determines whether a given line would end up in the game of 1st, 2nd, 3rd or 4th of arms, and you do not know the values that ROW_NUMBER will return: 1, 2, 3 and 4.

    I think you want something like this:

    WITH     got_c_num     AS
    (
         SELECT       group_number
         ,       division
         ,       class_col          -- CLASS is not a good column name
         ,       stage
         ,       endage
         ,       rate
         ,       ROW_NUMBER () OVER ( PARTITION BY  group_col
                                      ,          division
                               ,          class_col
                               ORDER BY          low_age
                                    )    AS c_num
         FROM      test
    --     WHERE       ...               -- If you need any filtering, put it here
    )
    SELECT       group_number,       division,       class_col
    ,       MIN (CASE WHEN c_num = 1 THEN stage  END)     AS a1
    ,       MIN (CASE WHEN c_num = 1 THEN endage END)     AS ae1
    ,       MIN (CASE WHEN c_num = 1 THEN rate   END)     AS rt1
    ...
    ,       MIN (CASE WHEN c_num = 4 THEN stage  END)     AS a4
    ,       MIN (CASE WHEN c_num = 4 THEN endage END)     AS ae4
    ,       MIN (CASE WHEN c_num = 4 THEN rate   END)     AS rt4
    ,       endage
    ,       rate
    FROM      got_c_num
    GROUP BY  group_number,       division,       class_col
    ORDER BY  group_number,       division,       class_col
    ;
    

    I make several assumptions about your table and your data.
    If post you some examples of data (CREATE TABLE and INSERT statements) and outcomes from these data, I was able to test this.

  • Filter

    Hello
    I have a report as X axis time and the values on the axis Y. I have to select names in the filter above table how to define the filter.
    Don't want to go dashboard or the command prompt.

    Thank you

    Hello

    PivotChart dynamic use
    and this column (which must show as a filter) in the part of pivot pages

    And why all the questions are in a State without an answer? are you sure that these threads do not respond. Otherwise, please close this message as answered will help others

    Published by: Kishore Guggilla January 5, 2011 19:09

Maybe you are looking for