Help of pivot/SUMIF

OK - rather than too many individual questions let me give an example for the experts of numbers (I just years of Excel)

Month

Date

Description

Original description

Amount

Transaction type

Category

Account name

April

April 13, 2016

Delta

DELTA AIR

$725,14

flow

Air transport

Visa1

April

April 11, 2016

Parking

PARKING

$46,97

flow

Air transport

Visa2

April

April 11, 2016

Southwest Airlines

SOUTHWESTAIR

$5.00

flow

Air transport

Visa1

April

April 19, 2016

DR. D

DR. D

$160.00

flow

Doctor

CREDIT CARD

April

April 19, 2016

Electric Company

Payment of invoice Electric Company

$378,89

flow

Electric

AUDIT OF

April

April 11, 2016

Amazon

AMAZON MKTPLACE

$15.66

flow

Electronics

Discover

April

April 1, 2016

New seasons

NEW SEASONS MARKET

$125,47

flow

Kitchen/food

Visa1

April

April 21, 2016

Publix

PUBLIX

$145,23

flow

Grocery

Visa2

April

April 13, 2016

Wal-Mart

Wal-Mart

$47.77

flow

Grocery

AUDIT OF

April

April 11, 2016

Apple

Apple

$497,65

flow

Leisure

Visa1

April

April 15, 2016

Holiday

HOLIDAY

$775,47

flow

Hotel

Visa1

April

April 12, 2016

Mark

PAYPAL

$100.00

flow

Hotel

AUDIT OF

April

April 8, 2016

Verizon

VERIZON

$115.55

flow

Phone, Internet, TV

AUDIT OF

April

April 19, 2016

Marchellos

MARCHELLOS

$38,87

flow

Pizza guy

CREDIT CARD

April

April 8, 2016

Tri-Met

TRIMET

$2.50

flow

Taxi & car rental

Visa2

April

April 4, 2016

The Rainbow market

THE RAINBOW MARKET

$21.25

flow

Grocery trip

Visa2

April

April 1, 2016

R O C

Bill R.O.C.C.

$67,40

flow

Water

COMMON CONTROL

April

April 2, 2016

Amazon

AMZ

$138,44

flow

Woot wine

Discover

Imagine the above sheet with many more lines, up to 12 months (of course) and many more categories.   I'm looking to create reports, by month, by category, with subtotals for amount from the category and month level.  If all goes well, a report that I will be able to easily create charts of.

In the days of Excel, it's all very easy by using PivotTables - not this the case with numbers, but I would like to learn from the example and use if possible numbers.

Not as easy as the PivotTable, drag-and-drop but not really that hard.  A formula in B2, you can fill out right and downwards.  Category separate names on the left. Names of months in the upper part.  I changed some months in your example of dataset to display

The names must match exactly.  Note that when you type in the names of months numbers automatically converts to a date-time value and the existence of the part of that time or the part of the date can cause confusing failures correspond to the year. It can be safer to type a "followed by the name of the month.  Which indicates the numbers to treat the name as text.

The formula in B2, filled to the right and downwards:

= SUMIFS(Table 1::$E,Table 1::$G,$A2,Table 1::$A,B$1)

You can learn more about the SUMIFS examples and see here.  It works with pairs of columns-condition.

SG

Tags: iWork

Similar Questions

  • Need help with PIVOT

    Hello

    First of all, let me apologize if this is in the wrong forum.

    I need assistance with pivot control in Oracle.  Here's what I'm trying to accomplish:

    Select persongroup , status , count(status) as tot

    de WorkOrder

    status in ('WSCH','WPLAN','WMATL','PLAN','APPR')

    et persongroup in ('K3P-GEN','K3P-ELEC','K3P-INST','K3P-MECH')

    Group of persongroup,State

    order by 1


    Results:


    K3P-ELEC APPROX. 12

    10 PLAN K3P-ELEC

    K3P-ELEC WMATL 10

    K3P-ELEC LEVELS 109

    K3P-ELEC WSCH 18

    K3P - GEN APPROX. 17

    PLAN OF K3P - GEN 59

    K3P - GEN WMATL 10

    K3P - GEN LEVELS 188

    K3P - GEN WSCH 22

    K3P-INST APPROX. 18

    K3P-INST PLAN 27

    K3P-INST WMATL 17

    K3P-INST LEVELS 60

    K3P-INST WSCH 40

    K3P-MECH APPROX. 4

    K3P-MECH 47 PLAN

    K3P-MECH WMATL 14

    K3P-MECH LEVELS 20

    K3P-MECH WSCH 52

    I want to see is:

    APPR WMATL LEVELS WSCH TOTAL PLAN

    K3P-ELEC 12 10 10 109 18 159

    K3P - GEN 17 59 10 188 22 296

    ......

    Using the above query I tried, but this is incorrect;

    Select * from (

    Select persongroup , status , count(status) as tot

    de workorder

    status in ('WSCH','WPLAN','WMATL','PLAN','APPR')

    et persongroup in ('K3P-GEN','K3P-ELEC','K3P-INST','K3P-MECH')

    Group of persongroup,State

    order by 1

      sum(3)

      for status in ('WSCH','WPLAN','WMATL','PLAN','APPR')

    order by 1



    Any help appreciated.


    Thank you


    Cameron

    You missed the "PIVOT" option, try this:

    SELECT *.

    FROM (SELECT Tot Persongroup, status, COUNTY (status)

    FROM Workorder

    WHERE Status IN ('WSCH', 'LEVELS', 'WMATL', 'PLAN', 'POPULAR')

    AND Persongroup IN ('K3P-ELEC","K3P-INST","K3P - GEN","K3P-MECH")

    Persongroup, status)

    PIVOT (SUM (Tot) for registered IN ('WSCH', 'LEVELS', 'WMATL', 'PLAN', 'POPULAR'))

    ORDER BY 1

    /

  • Help with pivot

    Hi all

    I have these sample data:

    create table mySample(
     myID   number,
     fy     number,
     idType varchar2(1),
     idCount number
      );
      
    insert into mySample(myID, fy, idType, idCount)
    values (1, 2010, 'A', 1);
    insert into mySample(myID, fy, idType, idCount)
    values (1, 2010, 'B', 0);
    insert into mySample(myID, fy, idType, idCount)
    values (1, 2010, 'B', 1);
    insert into mySample(myID, fy, idType, idCount)
    values (1, 2011, 'A', 1);
    insert into mySample(myID, fy, idType, idCount)
    values (1, 2011, 'A', 1);
    insert into mySample(myID, fy, idType, idCount)
    values (1, 2011, 'B', 1);
    insert into mySample(myID, fy, idType, idCount)
    values (1, 2011, 'A', 0);
    
    
    select *
    from (
         select myID, fy, idType
         from  mySample
    )
    pivot (count(*) for idType in ('A' as A_count, 'B' as B_count)
    )
    order by myID, fy
         
    

    My result of pivot is:

    MYID FY A_COUNT B_COUNT

    1 2010 1 2

    1 2011 3 1

    How can I get the total number of calls the idType and the total of idCount in the pivot?

    MYID FY A_COUNT B_COUNTTOTAL_COUNT TOTAL_ID_COUNT

    1 2010 1 2 3 2

    1 2011 3 1 4 3

    With the help of Oracle 11 g Release 11.2.0.4.0

    Thank you

    Hello

    Here's one way:

    Select myid, fy, a_count, b_count

    a_count + b_count AS total_count

    a_id_count + b_id_count AS total_id_count

    of mySample

    Pivot (count (*) AS count

    the sum (idCount) AS id_count

    for idType in (a, 'B' b 'A')

    )

    order by myID, fy

    ;

    Now that all the columns in the table play a certain role in the pivot, you need more online reviews. You can select directly from mySample.

    Output:

    MYID FY A_COUNT TOTAL_COUNT TOTAL_ID_COUNT B_COUNT

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

    1      2010          1          2          3              2

    1      2011          3          1          4              3

  • Requesting help with pivot in Oracle 10 g

    Hey all,.

    I have this table, call the table GRID that has the following columns:
    OBJECT_KEY             DATE_KEY               SEGMENT_ID             COLUMN_NAME COMMITTEDVIRTUALMEMORYSIZE_AVG 
    ---------------------- ---------------------- ---------------------- ----------- ------------------------------ 
    619                    3371                   1                      M1100       593589862.4                    
    619                    3371                   1                      M1105       593611434.67                   
    620                    3371                   1                      M1100       592354508.8                    
    620                    3371                   1                      M1105       592376263.11                   
    621                    3371                   1                      M1100       731433369.6                    
    621                    3371                   1                      M1105       731455943.11
    What would take to rotate the names of column ("M1100", "M1105") with the value metric volumn: "COMMITTEDVIRTUALMEMORYSIZE_AVG", so that this query would yield a result like this:
    OBJECT_KEY             DATE_KEY               SEGMENT_ID             M1100          M1105 
    ---------------------- ---------------------- ---------------------- -----          ------
    619                    3371                   1                      593589862.4     593611434.67                           
    620                    3371                   1                      592354508.8     592376263.11                           
    621                    3371                   1                      731433369.6     731455943.11
    Any help would be appreciated!
    Again, Oracle 10 g, 11g not so I don't have the PIVOT function to work with.


    Kind regards
    TimS
  • Help of pivot

    Here is an example of what I'm trying to do. I use Oracel 11 g.


    CREATE THE TEST TABLE
    (
    NUMBER OF ENTITY_ID,
    ENTITY_TYPE VARCHAR (25),
    MEASURE VARCHAR (25),
    NUMBER OF JAN,
    FEBRUARY ISSUE,
    MAR IN NUMBER,
    NUMBER OF THE APR,
    MAY ISSUE,
    JUNE ISSUE,
    ISSUE OF JULY,
    AUGUST ISSUE,
    NUMBER OF MS,
    NUMBER OF THE OCT,
    NUMBER OF NOV,
    NUMBER OF DEC
    );

    INSERT IN THE TEST
    VALUES (100, 'SERVICE', 'CASE', 146, 135, 148, 145, 170, 160, 198, 171, 172, 168, 159, 157);

    INSERT IN THE TEST
    VALUES (100, ' SERVICE ',' PATIENT DAYS ", 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260);


    The output I'm looking is as follows
    ENTITY_ID DT ENTITY_TYPE VALUE MEASUREMENT
    01/01/2012 100 SERVICE 146 CASES
    CASE OF SERVICE 01/02/2012 100 135
    01/03/2012 100 SERVICE CASE 148
    01/04/2012 100 CASES OF SERVICE 145
    01/05/2012 100 SERVICE 170 CASES
    01/06/2012 100 CASES OF SERVICE 160
    01/07/2012 100 SERVICE 198 CASES
    01/08/2012 100 SERVICE 171 CASES
    01/09/2012 100 CASES OF SERVICE 172
    01/10/2012 100 CASES OF SERVICE 168
    01/11/2012 100 SERVICE 159 CASES
    01/12/2012 100 SERVICE 157 CASES
    01/01/2012 100 PATIENT DAYS SERVICE 150
    01/02/2012 100 160 PATIENT-DAYS OF SERVICE

    and so on...

    Any help would be greatly appreciated. Thank you

    ChoMan23 wrote:
    Here is an example of what I'm trying to do. I use Oracel 11 g.

    http://www.Oracle-Developer.NET/display.php?ID=506

    Search for "Unpivot".

  • help request pivot with single quotes inside a string literal

    Hi all

    I have a little trouble with a pivot query. Oracle (10g R2) is:

    ORA-00604: an error occurred at recursive SQL level1
    ORA-01003: no instruction not analyzed

    My problem is pretty clear. When I do a pivot query to display a list of records where the countries are the column headers and rows headers is months that the system hesitates when she returns a country with an apostrophe in it. for example

    COUNTRY_NAME = ' KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF»

    I know that I have to catch the literal single quote and manipulate. I am just having unsuccessfully in management of it and I'm a little out of ideas. Can someone tell me a nice solution?

    The complete procedure is listed below: the


    PROCEDURE getCountryInvPlan)
    iINV_PLAN_DEPOT_ID in NUMBERS
    iITEM IN VARCHAR2,
    RC IN OUT pkg_DMT_INV_PLAN.t_rc,
    oErrorMsg OUT VARCHAR2)
    IS
    v_sql VARCHAR2 (32767).
    BEGIN


    v_sql: = 'select MONTH_BUCKET ';
    FOR rec IN
    (select distinct (COUNTRY_NAME) in the DMT_INV_PLAN_DEPOT_COUNTRY where INV_PLAN_DEPOT_ID = iINV_PLAN_DEPOT_ID)
    LOOP
    v_sql: = v_sql
    || ', MAX (DECODE (COUNTRY_NAME, "'))
    || recomm. COUNTRY_NAME
    || ((', PATIENT_DEMAND)) ' "»
    || recomm. COUNTRY_NAME
    || '"';
    END LOOP;
    v_sql: = v_sql
    || ', ' DECODE(MONTH_CLOSED,0,''OPEN'',1,''CLOSED'') AS MONTH_STATUS
    || ' FROM (SELECT DMT_INV_PLAN_DEPOT_COUNTRY. MONTH_BUCKET, DMT_INV_PLAN_DEPOT_COUNTRY. COUNTRY_NAME, DMT_INV_PLAN_DEPOT_COUNTRY. PATIENT_DEMAND, DMT_INV_PLAN_ITEM. DMT_INV_PLAN_DEPOT_COUNTRY MONTH_CLOSED, DMT_INV_PLAN_ITEM '
    || "where DMT_INV_PLAN_DEPOT_COUNTRY.". INV_PLAN_DEPOT_ID = DMT_INV_PLAN_ITEM. INV_PLAN_DEPOT_ID '
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. ITEM_DESCRIPTION = DMT_INV_PLAN_ITEM. ITEM_DESCRIPTION '
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. MONTH_BUCKET = DMT_INV_PLAN_ITEM. MONTH_BUCKET '
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. INV_PLAN_DEPOT_ID = ' | iINV_PLAN_DEPOT_ID
    || ' AND DMT_INV_PLAN_DEPOT_COUNTRY. ITEM_DESCRIPTION = "' | iITEM | " ') '
    || 'GROUP by MONTH_BUCKET order MONTH_BUCKET MONTH_CLOSED';
    RC OPEN FOR v_sql;

    oErrorMsg: = v_sql;

    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    oErrorMsg: = "NO DATA FOUND";

    WHILE OTHERS
    THEN
    oErrorMsg: = "ERROR";
    oErrorMsg: = v_sql;
    END getCountryInvPlan;

    Maybe you can try this:

    -- Etc --
    || ',MAX(DECODE(COUNTRY_NAME,'''
    || REPLACE(rec.COUNTRY_NAME,'''','''''')
    || ''',PATIENT_DEMAND)) "'
    || rec.COUNTRY_NAME
    || '"';
    -- Etc --
    

    8 2

  • The joins of data and help to Pivot

    Hi, I have a fact table and a table of huge story that will really with partitions stored with dates of end of month.

    I am looking for a way to manipulate the month and year of DateChanged to table the long interview with seal on the acct recover scores of the month previous, resulting in a format of standardized data such as in the result table.

    Any ideas? Thank you!


    Table A
    
    Acct     DateChanged
    -----------------------------------
    123     1/12/2008
    456     8/25/2008
     
    
    
    Table B:
     
    Acct           DateUpload        Score
    -----------------------------------------
    123           11/30/2007        620
    123           12/31/2007        650
    123           01/31/2008        712
    123           02/29/2008        800
    456           05/31/2008        520  
    456           06/30/2008        630
    456           07/31/2008        680
    456           08/31/2008        710
    456           09/30/2008        780
    456           10/31/2008        786
    456           11/30/2008        823
    
    
    
    Result Table:
                      
    Acct      Score2MonthPrior     Score1MonthPrior
    -------------------------------------------------------
    123            620                     650
    456            630                     680

    Hello

    Whenever you have any questions, post a small example of data in a form, in fact, people can use. CREATE TABLE and INSERT statements are the best. A clause WITH, like Solomon posted, is better than nothing. Without it, people will help you as much as they can, but do not expect to test anything.

    Using data of Solomon, I was able to test (and correct) my request.

    WITH     got_priormonth          AS
    (
         SELECT     a.acct
         ,     b.score
         ,     MONTHS_BETWEEN ( TRUNC (b.date_upload,  'MONTH')
                          , TRUNC (a.date_changed, 'MONTH')
                          )     AS priormonth     -- Alias added
         FROM     tableA  a
         JOIN     tableB     b     ON     a.acct     = b.acct
         WHERE     a.date_changed     >= ADD_MONTHS  ( TRUNC (b.date_upload, 'MONTH')
                                      , -2
                                    )
         AND     a.date_changed  <                TRUNC (b.date_upload, 'MONTH')
    )
    SELECT       acct
    ,       MAX (CASE WHEN priormonth = 2 THEN score ELSE 0 END)     AS score2monthprior
    ,       MAX (CASE WHEN priormonth = 1 THEN score ELSE 0 END)     AS score1monthprior
    FROM       got_priormonth
    GROUP BY  acct
    ;
    

    ORA-00907 actually means "absolutely free index to the subject of what you hear".
    Perhaps a missing closing parenthesis causes the error as much as anything, but when you get this error, look for any type of syntax error at (or just before) the specified point.

    You're right, I forgot the column alias. Sorry; If I could have it tested before posting, I would have.

  • Pivot and calculations

    Hi all

    Frank has been able to help me with this PivotTable:

    Help with pivot

    create table test_base_table (  
         FY           number,  
         FY_MONTH     number,  
         FIRST_VALUE  number,  
         SECOND_VALUE number);  
    insert into test_base_table values (2012, 1, 10, 100);  
    insert into test_base_table values (2012, 2, 20, 200);  
    insert into test_base_table values (2012, 3, 30, 300);  
    insert into test_base_table values (2013, 1, 15, 150);  
    insert into test_base_table values (2013, 2, 25, 250);  
    insert into test_base_table values (2013, 3, 35, 350); 
    
    

    Solution of query:

    
    SELECT    p.*                       
    ,         month_1 + month_2 + month_3  AS all_months 
    FROM      test_base_table
    UNPIVOT   (    val
              FOR  key  IN ( first_value   AS 'firstValue'
                           , second_Value  AS 'secondValue'
                           )
              )
    PIVOT     (    MIN (val)
              FOR  fy_month  IN ( 1  AS month_1
                                , 2  AS month_2
                                , 3  AS month_3
                                )
              ) p                                        
    ORDER BY  fy,   key
    ;
    
    

    Now, I'm doing some calculations:

    The first begin_calc of the first month is 800 (value) in another table.

    The end_calc is the sum of the begin_calc + firstValue + secondValue.

    The avg_value is the average of (firstValue + secondValue) / 2

    The begin_calc of the second month (month_02) is the end_calc of the month_01 of the previous month.

    The begin_calc of the last_month (month_03) is the begin_cal of the following year and so on.

    Is it possible to do this in SQL?

    Thank you!

    EXERCISE KEY MONTH_1 MONTH_2 MONTH_3 ALL_MONTHS

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

    2012 800-910-1130 begin_calc

    2012 10 20 30 60 firstValue

    secondValue 2012 100 200 300 600

    2012 910-1130-1460 end_calc

    2012 avg_value (10 + 100) / (20 + 200) 2 / 2

    begin_calc 2012-1460

    2013 15 25 35 75 firstValue

    2013 150 250 350 750 secondValue

    2013 910-1130-1460 end_calc

    avg_value 2013 (10 + 100) / 2 (20 + 200) / 2.

    Hello

    Here's one way:

    WITH got_aggregates AS

    (

    SELECT the year, fy_month, key

    The SUM (val) AS sum_val

    AVG (val) AS avg_val

    SUM (SUM (val)) (PARTITION BY KEY

    ORDER BY fy, fy_month

    )

    + (

    SELECT MAX (star_rate)

    RATES

    ) AS sum_so_far

    OF test_base_table

    UNPIVOT (val

    FOR key IN (first_value AS "firstValue"

    , second_value AS "secondValue".

    )

    )

    GROUP BY GROUPING SETS ((fy, fy_month, keys)

    (fy, fy_month)

    (fy, key)

    )

    )

    SELECT the exercise, 'begin_calc' AS a key

    MIN (CASE WHEN fy_month = 1 THEN sum_so_far - sum_val END) AS month_1

    MIN (CASE WHEN fy_month = 2 THEN sum_so_far - sum_val END) AS month_2

    MIN (CASE WHEN fy_month = 3 THEN sum_so_far - sum_val END) AS month_3

    ,         NULL                                                        AS all_months

    ,         ' '                                                         AS " "

    OF got_aggregates

    WHERE key IS NULL

    GROUP BY fiscal year

    UNION

    SELECT the year, key

    MIN (CASE WHEN fy_month = 1 THEN sum_val END) AS month_1

    MIN (CASE WHEN fy_month = 2 THEN sum_val END) AS month_2

    MIN (CASE WHEN fy_month = 3 THEN sum_val END) AS month_3

    MIN (CASE WHEN fy_month IS NULL THEN END sum_val) AS all_months

    ,         '  '                                                AS " "

    OF got_aggregates

    WHERE do I enter ("firstValue", "secondValue")

    GROUP BY fy, key

    UNION

    SELECT the exercise, 'end_calc' AS a key

    MIN (CASE WHEN fy_month = 1 THEN sum_so_far END) AS month_1

    MIN (CASE WHEN fy_month = 2 THEN sum_so_far END) AS month_2

    MIN (CASE WHEN fy_month = 3 THEN sum_so_far END) AS month_3

    NULL AS all_months

    ,         '   '                                             AS " "

    OF got_aggregates

    WHERE key IS NULL

    GROUP BY fiscal year

    UNION

    SELECT the exercise, 'avg_val' AS a key

    MIN (CASE WHEN fy_month = 1 THEN avg_val END) AS month_1

    MIN (CASE WHEN fy_month = 2 THEN avg_val END) AS month_2

    MIN (CASE WHEN fy_month = 3 THEN avg_val END) AS month_3

    NULL AS all_months

    ,         '    '                                         AS " "

    OF got_aggregates

    WHERE key IS NULL

    GROUP BY fiscal year

    --

    ORDER BY fy, "', key

    ;

    The result is what you asked:

    EXERCISE KEY MONTH_1 MONTH_2 MONTH_3 ALL_MONTHS

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

    2012 800-910-1130 begin_calc

    2012 10 20 30 60 firstValue

    secondValue 2012 100 200 300 600

    2012 910-1130-1460 end_calc

    2012 avg_val 55 110 165

    2013 1460-1625-1900 begin_calc

    2013 15 25 35 75 firstValue

    2013 150 250 350 750 secondValue

    2013 1625 1900 2285 end_calc

    avg_val 2013 82.5 137.5 192,5

    I'm not very satisfied with all the unions; There is probably a better way.

  • Help please - SUMIF formula?

    I have been using the model of budget numbers.  On Page 1, I have the summary, and my transactions are in two other tabs (a credit card) and one for the Bank.  SUMIF using I can get the category to display the total of one of the sheets, but I can't work on the formula if I want to use the amounts of the credit card and Bank at the same time sheets (hope that makes sense).  IE I want to have my grocery category to indicate the total amount spent for the credit card and the Bank.   Absolute beginner to this and my Mathematics studies completed years... I just try and follow the logical path.  Thanks in advance for any help

    Hi computermum,.

    If we look at the two personal Budget in 3 numbers,

    Formula in C2 (fill down)

    SUMIF(Transactions Credit Card::Transactions::C,A2,Transactions Credit Card::Transactions::$D) + SUMIF(Transactions Bank::Transactions::C,A2,Transactions Bank::Transactions::D) =

    Which use SUMIF for two sheets of Transactions (credit card and Bank).

    Built to illustrate:

    = SUMIF(Transactions Credit Card::Transactions::C,A2,Transactions Credit Card::Transactions::$D) (the original, adapted form for the name of the new 'Transactions credit card' journal)

    + (plus)

    SUMIF (Transactions Bank::Transactions:C, A2, Transactions Bank::Transactions:D) (SUMIF review for the journal of banking)

    Substitute member of the worksheet names that you are using.

    Note that my values in the column (column C) actual spending on the Budget sheet are double values in the model. I have been duplicated and rename the original Transactions.

    Kind regards

    Ian.

  • Pivot query help

    need help on creating pivot query

    SELECT * FROM TEST1

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

    VALUE OF PERSON COMPUTERNAME

    COMP1                    ABC                     3

    COMP2                    ABC                     5

    COMP1                    CAD                     3

    COMP3                    CAD                     5

    COMP2                    TES                      1

    COMP1                    TES                      5

    COMP3                    ABC                      2

    myQuery

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

    Select the link null, label, value1 COUNT (VALUE)

    from 'test1 '.

    CONTROL group PER PERSON

    Results

    ---------

    Link label value1

    -                     ABC                     3

    -                     CAD                     2

    -                     TES                      2

    My requirement

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

    can we have something like that out using the concept of pivot? If so can you share an example query pls.


    Link label value1

    -ABC ORDI1, COMP2, COMP3

    -CAD COMP1, COMP2

    -YOUR ORDI1, COMP3

    Hello

    Subhash C-Oracle wrote:

    need help on creating pivot query

    SELECT * FROM TEST1

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

    VALUE OF PERSON COMPUTERNAME

    COMP1                    ABC                    3

    COMP2                    ABC                    5

    COMP1                    CAD                    3

    COMP3                    CAD                    5

    COMP2                    TES                      1

    COMP1                    TES                      5

    COMP3                    ABC                      2

    myQuery

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

    Select the link null, label, value1 COUNT (VALUE)

    from 'test1 '.

    CONTROL group PER PERSON

    Results

    ---------

    Link label value1

    -                    ABC                    3

    -                    CAD                    2

    -                    TES                      2

    My requirement

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

    can we have something like that out using the concept of pivot? If so can you share an example query pls.

    Link label value1

    -ABC ORDI1, COMP2, COMP3

    -CAD COMP1, COMP2

    -YOUR ORDI1, COMP3

    This sounds like a job for LISTAGG:

    SELECT NULL AS link

    label

    LISTAGG (comp_name, ',')

    THE Group (ORDER BY ComputerName) AS value1

    OF test1

    GROUP BY label

    ;

    If you would care to post CREATE TABLE and INSERT statements for your sample data, then I could test it.

    Are you sure that the results you posted are what you want from data provided?

    Is of the order of the elements in a significant list?  In other words, when you say you want to get the results:

    COMP1, COMP2

    you'd be just as happy with

    ORDI1, COMP2

    ?  If the order is important, explains what this order.

  • MODEL/PIVOT: Help pls


    Hello

    I'm trying to convert rows into columns using model/Pivot in Oracle 11 g. Please find the details below.

    CREATE TABLE TEST_DATA_FIN
    (NUM NUMBER (9),)
    ID NUMBER (9),
    YEAR NUMBER 4.
    NUMBER VALUE (9.2))


    INSERT INTO TEST_DATA_FIN
    VALUES (1,100,2014, 1);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,100,2014, 2);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,100,2014, 3);
    INSERT INTO TEST_DATA_FIN
    VALUES (1,200,2014, 4);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,200,2014, 5);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,200,2014, 6);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,100,2013, 7);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,100,2013, 8);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,100,2013, 9);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,200,2013, 10);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,200,2013, 11);

    INSERT INTO TEST_DATA_FIN
    VALUES (1,200,2013, 12);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,100,2013, 13);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,100,2013, 14);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,100,2013, 15);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,200,2013, 16);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,200,2013, 17);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,200,2013, 18);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,100,2012, 19);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,100,2012, 20);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,100,2012, 21);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,200,2012, 22).

    INSERT INTO TEST_DATA_FIN
    VALUES (2,200,2012, 23);

    INSERT INTO TEST_DATA_FIN
    VALUES (2,200,2012, 24);

    For Ex,.
    NUM = 1
    IF MAX (YEAR) = 2014
    then a query that returns
    new columns
    NUM,
    ID,
    YEAR
    YEAR1_DATA with 1,
    YEAR2_DATA with 2,
    YEAR3_data with 3 and so on...

    For ex:
    NUM = 2
    IF MAX (YEAR) = 2013
    Then, the query must return
    new columns
    NUM                      = 2,
    ID,
    YEAR1_DATA 13,
    YEAR2_DATA 14,
    YEAR3_data with 15 and so on...

    The final output should be in the following format. Has managed to implement in Decode/Group by.  I am trying to write a query using MODEL/PIVOT.
    You can help me pls.


    NUM YEAR ID YEAR1_DATA YEAR2_DATA YEAR3_DATA

    --------------------------------------------------------------------------------------------------
    1        100    2014                  1                    2                           3
    1        200    2014                  4                    5                           6
    1        100    2013                  7                    8                           9

    2        200    2013                  10                  11                         12
    2        100    2013                  13                  14                        15
    2        200    2013                  16                  17                        18
    2        100    2012                   19                  20                       21
    2        200    2012                   22                  23                       24

    Thank you very much. I really appreciate any help.


    Hello

    946141 wrote:

    Thank you very much for your answers. I messed up the data bit. Very sorry about that.

    With the following data.

    Max (Year) value should go in YEAR1_DATA and MAX (YEAR) - 1 value should go in YEAR2_DATA.

    I am sorry once again and appreciate your help.

    The output should be as follows

    DIGITAL ID YEAR1_DATA YEAR2_DATA YEAR3_DATA

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

    1 100 33333 22222 11111

    1 200 44444 66666 55555

    2 100 333333 222222 111111

    2 200 4444444 666666 555555

    INSERT INTO TEST_DATA_FIN

    VALUES (1,100,2014, 33333);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,100,2013, 22222);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,100,2012, 11111);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,200,2014, 44444);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,200,2013, 66666);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,200,2012, 55555).

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

    INSERT INTO TEST_DATA_FIN

    VALUES (2,100,2013, 333333);

    INSERT INTO TEST_DATA_FIN

    VALUES (2,100,2012, 222222);

    INSERT INTO TEST_DATA_FIN

    VALUES (2,100,2011, 111111);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,200,2013, 4444444);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,200,2012, 666666);

    INSERT INTO TEST_DATA_FIN

    VALUES (1,200,2011, 555555);

    I think you want something like:

    WITH got_r_num AS

    (

    SELECT num, id, value

    , MAX (year) OVER (PARTITION BY num, id)

    -r_num year

    OF test_data_fin

    )

    SELECT *.

    OF got_r_num

    PIVOT (MIN (value)

    FOR r_num IN (0 AS year1_data

    1 AS year2_data

    2 UNDER year3_data

    )

    )

    ORDER BY num

    ,         id

    ;

    I don't see how you get the output you posted form data in the sample.  Will there be some typos in one or the other?

    For example, in the sample data, 100 is the only id associated with num = 2, so I don't understand the output line that is num = 2 and id = 200. I'm guessing that there is a mistake somewhere.

  • help in the application without using the pivot function

    Hi gurus,

    Can you please help write the query without using the PIVOT function.
     WITH indata AS
             (SELECT 1 sn, '123:456,789,323:456,213,344,345:5454' x
                from dual
              UNION ALL
              SELECT 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual),
            instr AS
             (SELECT a.SN,
                     rownum RN,
                     B.column_value || CASE
                       WHEN B.column_value NOT LIKE '%:%' THEN
                        ':'
                     END column_value 
                FROM indata a,
                     TABLE(CAST(multiset
                                (SELECT trim(SUBSTR(x,
                                                    (CASE LEVEL
                                                      WHEN 1 THEN
                                                       1
                                                      ELSE
                                                       instr(x, ',', 1, LEVEL - 1) + 1
                                                    END),
                                                    (CASE instr(x, ',', 1, LEVEL)
                                                      WHEN 0 then
                                                       4000
                                                      ELSE
                                                       instr(x, ',', 1, LEVEL) - 1 -
                                                       (CASE LEVEL
                                                          WHEN 1 THEN
                                                           0
                                                          ELSE
                                                           instr(x,
                                                                 ',',
                                                                 1,
                                                                 level - 1)
                                                        END)
                                                    END)))
                                   FROM dual
                                 CONNECT BY level <=
                                            LENGTH(x) -
                                            LENGTH(REPLACE(x, ',', '')) + 1) AS
                                sys.odcivarchar2list)) b)
            SELECT  col1_val2,
                    col1_val1,
                    col2_val2,
                    col2_val1,              
                   systimestamp
              FROM (select SN,
                          ROW_NUMBER() over(partition by SN order by RN) RN,
                           SUBSTR(column_value, INSTR(column_value, ':') + 1) VAL1,
                           substr(column_value, 1, instr(column_value, ':') - 1) val2
                      FROM instr ) PIVOT(MAX(VAL1) VAL1, MAX(VAL2) VAL2 FOR SN IN(1 as col1,2 as col2));
    Thanks in advance!...

    Any help would be appreciated.

    user590978 wrote:

    Can you please help write the query without using the PIVOT function.

    with indata as (
                    select 1 sn,'123:456,789,323:456,213,344,345:5454' x from dual union all
                    select 2, 'abcd:fgrfr,rfrf,rfred,tg:tg,tg:ophhh,op,vdfgbh:poijn' x from dual
                   ),
             t1 as (
                    select  x
                      from  indata
                      where sn = 1
                   ),
             t2 as (
                    select  x
                      from  indata
                      where sn = 2
                   ),
             t3 as (
                    select  level lvl,
                            substr(
                                   x,
                                   instr(',' || x,',',1,level),
                                   instr(x || ',',',',1,level) - instr(',' || x,',',1,level)
                                  ) col1
                      from  t1
                      connect by level <= length(x) - length(translate(x,'A,','A')) + 1
                   ),
             t4 as (
                    select  level lvl,
                            substr(
                                   x,
                                   instr(',' || x,',',1,level),
                                   instr(x || ',',',',1,level) - instr(',' || x,',',1,level)
                                  ) col2
                      from  t2
                      connect by level <= length(x) - length(translate(x,'A,','A')) + 1
                   ),
             t5 as (
                    select  lvl,
                            substr(col1,1,instr(col1 || ':',':') - 1) col1_val1,
                            substr(col1,instr(col1 || ':',':') + 1) col1_val2
                      from  t3
                   ),
             t6 as (
                    select  lvl,
                            substr(col2,1,instr(col2 || ':',':') - 1) col2_val1,
                            substr(col2,instr(col2 || ':',':') + 1) col2_val2
                      from  t4
                   )
    select  col1_val1,
            col1_val2,
            col2_val1,
            col2_val2,
            systimestamp
      from      t5
            full join
                t6
            on (
                t6.lvl = t5.lvl
               )
      order by coalesce(t5.lvl,t6.lvl)
    /
    
    COL1_VAL1  COL1_VAL2  COL2_VAL1  COL2_VAL2  SYSTIMESTAMP
    ---------- ---------- ---------- ---------- -------------------------------------
    123        456        abcd       fgrfr      23-OCT-12 11.50.12.015000 AM -04:00
    789                   rfrf                  23-OCT-12 11.50.12.015000 AM -04:00
    323        456        rfred                 23-OCT-12 11.50.12.015000 AM -04:00
    213                   tg         tg         23-OCT-12 11.50.12.015000 AM -04:00
    344                   tg         ophhh      23-OCT-12 11.50.12.015000 AM -04:00
    345        5454       op                    23-OCT-12 11.50.12.015000 AM -04:00
                          vdfgbh     poijn      23-OCT-12 11.50.12.015000 AM -04:00
    
    7 rows selected.
    
    SQL> 
    

    SY.

  • Help with a query of the pivot hierarchy

    I looked in the FAQ, but I'm just not see it.
    I have the following:

    A request for return:
    o_id   oname            typ  prnt
    118    Pension Admin    PRC    91
    91     Retirement       LOB   218
    218    Benefits         SEG    81
    119    Plan Mgmt        PRC    91
    91     Retirement       LOB   218
    218    Benefits         SEG    81
    142    RCS Software     PRC    93
    93     Risk Software    LOB   221
    221    Risk Services    SEG    81
    I want the following:
    ID  PRC              LOB               SEG
    118 Pension Admin    Retirement        Benefits
    119 Plan Mgmt        Retirement        Benefits
    142 RCS Software     Risk Software     Risk Services
    Version:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    AMT for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    Sample data:
    create table t1( o_id  number(3)
                   , oname varchar2(20)
                   , typ  varchar2(3)
                   , prnt number(3)
                   );
    
    insert into t1 values(118,   'Pension Admin',  'PRC',  91);
    insert into t1 values(91,    'Retirement',     'LOB', 218);
    insert into t1 values(218,   'Benefits',       'SEG',  81);
    insert into t1 values(119,   'Plan Mgmt',      'PRC',  91);
    insert into t1 values(142,   'RCS Software',   'PRC',  93);
    insert into t1 values(93,    'Risk Software',  'LOB', 221);
    insert into t1 values(221,   'Risk Services',  'SEG',  81);
    I can't go beyond:
    select level lvl, org.*
      from t1 org
      start with typ = 'PRC'
      connect by  o_id =  prior prnt;
    I tried this, but of course she returns only a single line:
    select *
      from (
             select lvl, oname
               from (  
                      select level lvl, t1.*
                        from t1 
                       start with typ = 'PRC'
                     connect by  o_id =  prior prnt
                    )    
           )
    pivot ( min(oname)  for lvl in (1  prc, 2 lob, 3 seg) )
    What escapes me, any help would be appreciated.
    with org as (
                 select  connect_by_root o_id o_id,
                         oname,
                         typ
                   from  t1
                   start with typ = 'PRC'
                   connect by  o_id =  prior prnt
                )
    select  *
      from  org
      pivot(
            max(oname) for typ in('PRC' PRC,'LOB' LOG,'SEG' SEG)
           )
    /
    
          O_ID     PRC                      LOG                      SEG
    ----------     --------------------     --------------------     --------------------
           119     Plan Mgmt                Retirement               Benefits
           142     RCS Software             Risk Software            Risk Services
           118     Pension Admin            Retirement               Benefits
    
    SQL> 
    

    SY.

  • Help with several table Pivot

    Oracle 11.2.0.1

    Windows

    create table tab1

    (

    Identification number,

    number of Java,

    number of DotNet,

    The Oracle number,

    number of MSSQL,

    number of php

    )

    /

    insert into tab1 values (1,10,20, null, 30, null);

    insert into tab1 values (2, null, 20, 30, null, null);

    insert into tab1 values (3,10,20,30,40,50);

    insert into tab1 values (4, null, null, null, null, null);

    create table tab2

    (

    Identification number,

    number of Java,

    number of DotNet,

    The Oracle number,

    number of MSSQL,

    number of php

    )

    /

    insert into values tab2 (1,10,20, null, 30, 40);

    Enter tab2 values (2, null, 20, 30, null, null);

    insert into values tab2 (3,10,20, null, 40, null);

    Enter tab2 values (4, null, 20, null, null, null);

    SQL > select * from tab1;

    ID DOTNET ORACLE MSSQL PHP JAVA

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

    1         10         20                    30

    2                    20                    30

    3         10         20         30         40         50

    4

    SQL > select * from tab2.

    ID DOTNET ORACLE MSSQL PHP JAVA

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

    1         10         20                    30         40

    2                    20                    30

    3         10         20                    40

    4                    20

    SQL >

    Power required:

    ID DOTNET ORACLE MSSQL PHP JAVA

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

    1-10-20 - 30 - <-table Tab1

    10-20 - 30 40 <-table Tab2

    < < < < A LINE VIRGIN > > >

    2        ---         20        ---         30        ---

    ---         20        ---         30        ---

    < < < < A LINE VIRGIN > > >

    3         10         20         30         40         50

    10         20        ---         40        ---

    < < < < A LINE VIRGIN > > >

    4        ---        ---        ---        ---        ---

    ---         20        ---        ---        ---

    Thank you.

    You need not pivot for this. The pivot is something completely different. Use weighted UNION ALL:

    with t1 as)

    Select tab1.*,

    1 weight

    of tab1

    Union of all the

    Select tab2.*,

    2 weight

    of the tab2

    ),

    T2 as)

    Select *.

    from t1

    Union of all the

    Select distinct id,

    Java NULL,

    dotnet null,

    Oracle NULL,

    MSSQL null,

    PHP null,

    3 weight

    from t1

    )

    Select the weight of case

    When 1 then id

    identifier of the end.

    Java,

    DotNet,

    Oracle,

    MSSQL,

    PHP

    the t2

    order by t2.id

    T2. Weight

    /

    ID DOTNET ORACLE MSSQL PHP JAVA
    ---------- ---------- ---------- ---------- ---------- ----------
    1         10         20                    30
    10         20                    30         40

    2                    20                    30
    20                    30

    3         10         20         30         40         50
    10         20                    40

    4
    20

    ID DOTNET ORACLE MSSQL PHP JAVA
    ---------- ---------- ---------- ---------- ---------- ----------

    12 selected lines.

    Scott@pdborcl12 >

    SY.

  • Help on SQL Pivot


    Hi gurus,
    I have req where I need to make the comparison between the Bill of trial ordinary bill vs. I need to get the test of the previous months and the latest current_month and 2 months of regular bills. Here are the th sample data.


    Account # Invc # Start_Date end_date regular_Amoun t Trial_Amount
    1233456 26470000 June 1, 2013 July 1, 2013 $19 27
    1347589 26470000 August 1, 2013 current_date $45 67
    1115756 26470000 may 1, 2013 July 1, 2013 $39 27

    This is the desired output

    Account # Invc # June 2013, July, 2013 August 2013
    1233456 26470000 $39 19 $ $67

    Any contribution is appreciated

    Hello

    Depending on your needs, here's a way:

    WITH got_month_num AS

    (

    SELECT account # invc #, regular_amount, trial_amount

    TRUNC (MONTHS_BETWEEN (start_date

    ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'),

    - 3

    )

    )

    ) AS month_num

    FROM table_x

    WHERE the arguments start_date > = ADD_MONTHS (TRUNC (SYSDATE, 'MONTH'),-2)

    AND start_date<  add_months="" (trunc="" (sysdate,="" 'month'), ="">

    )

    SELECT MIN (CASE WHEN month_num = 2 THEN accountt # END) AS account #.

    invc #.

    SUM (CASE WHEN month_num = 1 THEN regular_amount END) AS month_before_last

    SUM (CASE WHEN month_num = 2 THEN regular_amount END) AS last_month

    SUM (CASE WHEN month_num = 1 THEN trial_amount END) AS this_month\

    OF got_month_num

    GROUP BY invc #.

    ;

    It would take to get the columns as AUG_2013 dynamic SQL alias.  Your front end can help with that.  In SQL * Plus, for example, you can use substitution variables.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Point where the above query is incorrect results, and explain, using specific examples, how you get the right result of data provided in these places.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).  In this problem, what front-end you use (for example, SQL * Plus version 10) may also be important.

    See the FAQ forum: https://forums.oracle.com/message/9362002

Maybe you are looking for