PIVOT sql help

Hi again
I need some PIVOT sql help
In this query:
SELECT
SUM([RATES]) as RATES
,SUM([CONVERSION])as CONVERSION
FROM REPORTING
outputs
RATES CONVERSION
23 234
How would change this query to display a table like:
Name Amount
RATES 23
CONVERSION 234
Keep up the good work !

nikos101 wrote:
> How would change this query to display a table like:
Do you *HAVE* to change the query... you could just display
it in the
desired format if that it the ultimate and only goal.
<table>
<tr>
<td>name</td>
<td>amount</td>
</tr>
<cfoutput query="sumQry">
<tr><td>Rates</td><td>#rates#</td></tr>
<tr><td>Conversion</td><td>#conversion#</td></tr>
</cfoutput>
</table>

Similar Messages

  • Help with SQL to Pivot SQL

    I have requirment to build the SQL to Merge rows value to a single value.
    Here is the Data
    TABLE_A
    ID SEQ MESG
    1 1 MSG1
    1 2 MSG2
    2 1 MSG1
    3 1 MSG1
    3 2 MSG2
    3 3 MSG3
    I need output as
    ID MSG
    1 MSG1 MSG2
    2 MSG1
    3 MSG1 MSG2 MSG3

    Create function like below:
    CREATE OR REPLACE  FUNCTION rowtocol( p_slct IN VARCHAR2, p_dlmtr IN VARCHAR2 DEFAULT ',' ) RETURN VARCHAR2
    AUTHID CURRENT_USER AS
        TYPE c_refcur IS REF CURSOR;
        lc_str VARCHAR2(4000);
        lc_colval VARCHAR2(4000);
        c_dummy c_refcur;
        l number;
    BEGIN
        OPEN c_dummy FOR p_slct;
        LOOP
        FETCH c_dummy INTO lc_colval;
        EXIT WHEN c_dummy%NOTFOUND;
        lc_str := lc_str || p_dlmtr || lc_colval;
        END LOOP;
        CLOSE c_dummy;
        RETURN SUBSTR(lc_str,2);
           EXCEPTION
           WHEN OTHERS THEN
              lc_str := SQLERRM;
              IF c_dummy%ISOPEN THEN
              CLOSE c_dummy;
              END IF;
           RETURN lc_str;
    END;
    /And print result like :
       SELECT DISTINCT  a.job,
          rowtocol(  'SELECT ename  FROM emp
                           WHERE
                           job = ' || '''' || a.job || '''' || ' ORDER BY ename'
         AS Employees
        FROM emp;

  • SQL pivot query help

    HUM ADG DYS (NIA, SIM, TRC, TRX) SMALL BRANDS (LUP, KAL,CRN,LPP,SYN)
    MON TUE WED THURS FRI MON TUE WED THURS FRI MON TUE WED THURS FRI MON TUE WED THURS FRI
    VENDOR
    INT
    QUAN
    STER
    LASH
    OSP
    HIB
    PROD
    I’d like to put together a query to populate the tables above,like count of recods for each vendor for each brand with the criteria for selecting within one week.
    Here vendor_cd(INT,QUAN,STER,...etc),brand_cd(HUM,ADG,NIA,SIM,..eyc).we are extracting the details from file detail table whose column are like FILE_ID,FILE_RECEIPT_TS,REC_INSERT_TS,VENDOR_CD,BRAND_CD,RECORD_COUNT.
    Edited by: ASHWINI89 on Mar 21, 2013 8:33 PM

    Welcome to the forum!!
    Please consider the following when you post a question. This would help us help you better
    1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
    You can use the following query and do a copy past of the output.
    select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
    that are asked the answer is already there.
    3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
    I have the following table called sales
    with sales
    as
          select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
          union all
          select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
    select *
      from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
    For example in the above sales table, I want to know the total quantity and number of invoice for each product.
    The output should look like this
    Prod_id   sum_qty   count_inv
    1         145       2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
    6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
    Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
    use the {noformat}{noformat} tags.
    The usage of the tag is like this.
    <place your code here>\
    7. If you are posting a *Performance Related Question*. Please read
       {thread:id=501834} and {thread:id=863295}.
       Following those guide will be very helpful.
    8. Please keep in mind that this is a public forum. Here No question is URGENT.
       So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help, Pivot SQL

    I am doing a report for a book store. We have data like:
    STORE_ID SUBJECT     SUB_DETAIL     NUMBERS
    1001     CD     CD_TITLE1     2
    1001     CD     CD_TITLE2     4
    1001     CD     CD_TITLE3     1
    1001     DVD     DVD_TITLE1     7
    1001     DVD     DVD_TITLE2     5
    1001     DVD     DVD_TITLE3     3
    1001     DVD     DVD_TITLE4     2
    1001     BOOK     BOOK_TITLE1     6
    1001     BOOK     BOOK_TITLE2     2
    1001     OTHERS     OTHERS1     9
    1001     OTHERS     OTHERS2     1
    1001     OTHERS     OTHERS3     8
    1001     OTHERS     OTHERS4     2
    1001     OTHERS     OTHERS5     3
    We want to display the data like:
    STORE_ID CD CD_NUM DVD DVD_NUM BOOK BOOK_NUM OTHERS     OTHERS_NUM
    It can not show the format I want.
    Thanks a lot for any help!
    Jeanne

    nikos101 wrote:
    > How would change this query to display a table like:
    Do you *HAVE* to change the query... you could just display
    it in the
    desired format if that it the ultimate and only goal.
    <table>
    <tr>
    <td>name</td>
    <td>amount</td>
    </tr>
    <cfoutput query="sumQry">
    <tr><td>Rates</td><td>#rates#</td></tr>
    <tr><td>Conversion</td><td>#conversion#</td></tr>
    </cfoutput>
    </table>

  • SQL Help -- Need help with pivoting the columns to rows

    I have a requierement to split the columns into multiple rows. For example:
    EMP_DEPT
    rowid empid1 ename1 dept1 empid2 ename2 dep2 empid2 ename2      dep3 empid4 ename4 dept4
    100001 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER'     10 4 SMITH 20
    100002 1 'SCOTT' 10 2 'DAVE' 20 3 'MILLER'     20      
    Note: EMP_DEPT may not always have all the 4 employee info populated for example in row 2 only 3 employees info is there
    I need to convert it and insert into EMPLOYEE table as follows:
    EMPLOYEE
    empid ename dept
    1 SCOTT 10
    2 DAVE 20
    3 MILLER 10
    4 SMITH 20
    1 SCOTT 10
    2 DAVE 20
    3 MILLER 20
    Thanks
    Kev

    Frank Thank You for your response.
    I am on oracle 10gR2.
    Posting some sample DDL and data here as requested:
    CREATE TABLE EMP
      PK          NUMBER(10),
      EMP_NAME1   VARCHAR2(100 BYTE),
      EMP_ID1     NUMBER(10),
      EMP_NAME2   VARCHAR2(100 BYTE),
      EMP_ID2     NUMBER(10),
      DEPT_NAME1  VARCHAR2(200 BYTE),
      DEPT_ID1    NUMBER(10),
      DEPT_NAME2  VARCHAR2(200 BYTE),
      DEPT_ID2    NUMBER(10)
    CREATE TABLE EMP_DEPT
    ( PK NUMBER(10),
    ENTY_TYPE VARCHAR2(100),
    ENTY_NAME VARCHAR2(100),
    ENTY_ID NUMBER(10)
    Insert into EMP
       (PK, EMP_NAME1, EMP_ID1, EMP_NAME2, EMP_ID2, DEPT_NAME1, DEPT_ID1, DEPT_NAME2, DEPT_ID2)
    Values
       (1, 'SCOTT', 10001, 'FRANK', 10002,
        'MARKETING', 10, 'ACCOUNTING', 20);
    Insert into EMP
       (PK, EMP_NAME1, EMP_ID1, EMP_NAME2, EMP_ID2, DEPT_NAME1, DEPT_ID1)
    Values
       (2, 'SCOTT1', 10003, 'FRANK1', 10004,
        'MARKETING1', 30);
    COMMIT;
    SELECT
    FROM
    EMP;
    PK     EMP_NAME1     EMP_ID1     EMP_NAME2     EMP_ID2          DEPT_NAME1     DEPT_ID1     DEPT_NAME2     DEPT_ID2
    1     SCOTT          10001     FRANK          10002          MARKETING     10          ACCOUNTING     20
    2     SCOTT1          10003     FRANK1          10004          MARKETING1     30               My requirement is to:
    SELECT from emp and INSERT INTO EMP_DEPT so that columns are broken into rows as follows
    PK ENTY_TYPE, ENTY_NAME    ENTY_ID
    1  EMPLOYEE   SCOTT        10001
    2  EMPLOYEE   FRANK        10002
    3  DEPARTMENT MARKETING    10
    4  DEPARTMENT ACCOUNTING   20    
    5  EMPLOYEE   SCOTT1       10003
    6  EMPLOYEE   FRANK1       10004
    7  DEPARTMENT MARKETING1   30          Thanks
    Kevin
    Edited by: user10210466 on Dec 8, 2010 1:37 PM

  • Pivot sql year/month/category

    Need help with this :
    Requirement : need to pivot data based on year, month and display the sales correctly. if the data for any month does not exist that month shoudl not appear in the results.
    Sample data :
    --DROP TABLE APPS.TEST_OM_V CASCADE CONSTRAINTS;
    CREATE TABLE APPS.TEST_OM_V
    TAX_CATEGORY VARCHAR2(250 BYTE),
    SHIP_FROM_ORG_NAME VARCHAR2(100 BYTE),
    SCHEDULE_SHIP_DATE DATE,
    UNIT_SELLING_PRICE NUMBER,
    ORDERED_QUANTITY NUMBER,
    INVOICED_SALES NUMBER
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('Operating Supplies', 'DC FONT (FONT-120)', TO_DATE('02/01/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 12, 13,
    23);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('COFFEE', 'DC CANADA (CAN-180)', TO_DATE('09/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 90, 7,
    23.34);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('COFFEE', 'DC Florida (FLO-180)', TO_DATE('09/14/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 30, 8,
    75);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('COFFEE', 'DC CANADA (CAN-180)', TO_DATE('10/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 30, 2,
    100.11);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('COFFEE', 'DC CANADA (CAN-180)', TO_DATE('08/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 30, 2,
    75);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('Operating Supplies', 'DC DIST (DIS-130)', TO_DATE('10/21/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 12, 13,
    23);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('COFFEE', 'DC CANADA (CAN-180)', TO_DATE('08/30/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 30, 2,
    75);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('Operating Supplies', 'DC CANADA (CAN-180)', TO_DATE('01/02/2012 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 23, 1,
    45);
    Insert into APPS.TEST_OM_V
    (TAX_CATEGORY,
    SHIP_FROM_ORG_NAME, SCHEDULE_SHIP_DATE, UNIT_SELLING_PRICE, ORDERED_QUANTITY, INVOICED_SALES)
    Values
    ('Operating Supplies', 'DC PACK (PK-160)', NULL, 1, 2,
    1);
    COMMIT;
    Expected result , or anything close to this :
                                                                                2011                                     2012
                                                                   AUG      SEP          OCT         JAN   FEB      UNSCHEDULED
      COFFEE
                                    DC CANADA (CAN-180)          -30         606.66    -40.11         0          0          0
                                    DC Florida (FLO-180)          0           165         0           0          0          0
    Operating Supplies
                                    DC CANADA (CAN-180)           0           0            0         -22        0          0
                                    DC DIST (DIS-130)             0           0            133         0         0          0
                                    DC FONT (FONT-120)            0           0            0           0         133        0
                                    DC PACK (PK-160)              0           0            0           0          0           1 I tried grouping and summing and then lost my way...
    select TAX_CATEGORY, SHIP_FROM_ORG_NAME, nvl(TO_CHAR((SCHEDULE_SHIP_DATE), 'MM/YYYY'),'N/A') SCHEDULE_SHIP_DATE,
    sum((unit_selling_price * ORDERED_QUANTITY ) - nvl(INVOICED_SALES,0)) CARRYOVER
    from XXCNC.TEST_OM_V where 1=1
    group by TAX_CATEGORY, SHIP_FROM_ORG_NAME,nvl(TO_CHAR((SCHEDULE_SHIP_DATE), 'MM/YYYY'),'N/A')
    order by 1,2,3;
    Thanks for your help in advance.
    J

    Like this?:
    SQL> set num 6 lin 120 trims on
    SQL> col tax_category for a20
    SQL> col SHIP_FROM_ORG_NAME for a32
    SQL> break on tax_category
    SQL> SELECT *
      2  FROM (SELECT tax_category,
      3               ship_from_org_name,
      4               NVL( TO_CHAR( ( schedule_ship_date ), 'MM/YYYY' ), 'N/A' ) schedule_ship_date,
      5               ( unit_selling_price * ordered_quantity ) - NVL( invoiced_sales, 0 ) carryover
      6        FROM test_om_v) PIVOT (SUM( carryover )
      7                        FOR schedule_ship_date
      8                        IN  ('08/2011' AS "Aug'11",
      9                            '09/2011' AS "Sep'11",
    10                            '10/2011' AS "Oct'11",
    11                            '11/2011' AS "Nov'11",
    12                            '12/2011' AS "Dec'11",
    13                            '01/2012' AS "Jan'12",
    14                            '02/2012' AS "Feb'12",
    15                            'N/A' AS "UNSCHEDULED"))
    16  ORDER BY 1, 2, 3
    17  /
    TAX_CATEGORY         SHIP_FROM_ORG_NAME               Aug'11 Sep'11 Oct'11 Nov'11 Dec'11 Jan'12 Feb'12 UNSCHEDULED
    COFFEE               DC CANADA (CAN-180)                 -30 606.66 -40.11
                         DC Florida (FLO-180)                       165
    Operating Supplies   DC CANADA (CAN-180)                                                    -22
                         DC DIST (DIS-130)                                 133
                         DC FONT (FONT-120)                                                            133
                         DC PACK (PK-160)                                                                            1
    6 rows selected.:p
    Edited by: LKBrwn_DBA on Dec 16, 2011 12:18 PM

  • Pivot query help

    Hi All,
    I have a table as
    Create table carClass (
    carClassID  number,
    carID        number,
    baseYear   number, --Base Year
    Year_0      number, --Total for Base year
    Year_1      number, --Total for Base year minus 1
    Year_2      number ) --Total for Base year minus 2
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 1,1,2010,10,5,3);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 1,1,2013,12,3,2);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 1,2,2019,20,10,5);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 2,1,2014,25,12,6);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 2,2,2011,8,4,2);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 2,3,2012,9,6,3);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 3,1,2015,14,7,4);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 3,2,2017,12,9,8);
    insert into carClass (carClassID, carID, baseYear, Year_0, Year_1, Year_2)     values ( 3,2,2015,16,14,2);If Base year column "baseYear" is 2014, Year_0 total is for year 2014, Year_1 total is for year 2013 and Year_2 total is for year 2012.
    I would like to SUM the total for all carClass except for carClassID = 3 that I want the totals base on CarID
    The result is:
    Class CarID     2008     2009     2010     2011     2012     2013     2014     2015     2016     2017     2018     2019
    1          3     5     12     3     12     0     0     0     0     5     10     20
    2          0     2     7     14     9     0     0     0     0     0     0     0
    3     1     0     0     0     0     0     4     7     14     0     0     0     0
    3     2     0     0     0     0     0     2     14     24     9     12     0     0Any help will be appreciate.
    Thanks!

    Hi,
    Whenever you have a question, please say which version of Oracle you're using. This is especially important with pivot problems, because the SELECT ... PIVOT and SELECT ... UNPIVOT features, both of which could be used in this problem, were only introduced in Oracle 11.1.
    Here's one way:
    WITH   cntr           AS
         SELECT     LEVEL - 1     AS n
         FROM     dual
         CONNECT BY     LEVEL     <= 3
    ,     unpivoted_data     AS
         SELECT     cc.carClassID
         ,     CASE
                  WHEN  cc.carClassID = 3
                  THEN  cc.carID
              END               AS carID3
         ,     cc.baseYear - cn.n     AS yr
         ,     CASE  cn.n
                  WHEN  0  THEN  cc.year_0 
                  WHEN  1  THEN  cc.year_1 
                  WHEN  2  THEN  cc.year_2 
              END               AS amt
         FROM          carClass  cc
         CROSS JOIN     cntr       cn
    SELECT       carClassID, carID3
    ,       SUM (CASE WHEN yr = 2008 THEN amt ELSE 0 END)     AS yr2008
    ,       SUM (CASE WHEN yr = 2009 THEN amt ELSE 0 END)     AS yr2009
    ,       SUM (CASE WHEN yr = 2010 THEN amt ELSE 0 END)     AS yr2010
    ,       SUM (CASE WHEN yr = 2019 THEN amt ELSE 0 END)     AS yr2019
    FROM       unpivoted_data
    GROUP BY  carClassID, carID3
    ORDER BY  carClassID
    ;The results I get:
    CARCLASSID     CARID3     YR2008     YR2009     YR2010     YR2019
             1                     3          5         10         20
             2                     0          2          7          0
             3          1          0          0          0          0
             3          2          0          0          0          0aren't exqactly what you posted. That could be due to typos in your message. If not, point out where the results are wrong, and explain, step by step, how you figure the correct results in those places.
    Since I don't know which version of Oracle you're running, I only used features that are available in Oracle 9.1. Of course, this works in all later versions as well.
    In SQL, the number of columns and their aliases (such as yr2008) has to be hard-coded into any query.
    If you want the query itself to determine how many different years there are, and what those years are, then see {message:id=3527823}

  • XML - PL/SQL help

    Hello,
    I am having a query as a part of my procedure block that extracts the following xml and stores it into a variable that is of xmltype:
    <FeatureRoot>
    <Feature>
    <FeatureName>qaz</FeatureName>
    <FeatureAction>Add</FeatureName>
    </Feature>
    <Feature>
    <FeatureName>wsx</FeatureName>
    <FeatureAction>Remove</FeatureAction>
    </Feature>
    </FeatureRoot>
    Now what i want to do is loop through this variable (which is of xmltype) and print the values of the tags <FeatureName> and <FeatureAction> for every Feature.
    (ie)
    qaz Add
    wsx Remove
    Can you please tell me how i can loop through to extract the values?
    Many Thanks,
    Kalyani

    user11912174 wrote:
    Hello,
    Thank you. The solutions may hold good on a normal context. What my problem is I want to run a loop through an anonymous block in pl/sql where I am already using a cursor where each record contains an xml value as above. So i need to be extracting for each run in a cursor. So i need to be extracting the <FeatureName> and <featureaction> values in each cursor run. Any help on this?
    ThanksCan you not incorporate it as part of the cursor itself?
    It can return the values as part of the data from the cursor rather than using PL/SQL extracts on the XML to do it.
    SQL> ed
    Wrote file afiedt.buf
      1  with myxml as
      2    (select xmltype('<FeatureRoot>
      3                       <Feature>
      4                         <FeatureName>qaz</FeatureName>
      5                         <FeatureAction>Add</FeatureAction>
      6                       </Feature>
      7                       <Feature>
      8                         <FeatureName>wsx</FeatureName>
      9                         <FeatureAction>Remove</FeatureAction>
    10                       </Feature>
    11                     </FeatureRoot>') myxml from dual union all
    12     select xmltype('<FeatureRoot>
    13                       <Feature>
    14                         <FeatureName>aaa</FeatureName>
    15                         <FeatureAction>Add</FeatureAction>
    16                       </Feature>
    17                       <Feature>
    18                         <FeatureName>bbb</FeatureName>
    19                         <FeatureAction>Remove</FeatureAction>
    20                       </Feature>
    21                     </FeatureRoot>') from dual)
    22  select extractvalue(VALUE(t),'/Feature/FeatureName') featurename
    23  ,      extractvalue(VALUE(t),'/Feature/FeatureAction') featureaction
    24  from   myxml x
    25* ,      table(xmlsequence(extract(x.myxml,'/FeatureRoot/Feature'))) t
    SQL> /
    FEATURENAME     FEATUREACTION
    qaz             Add
    wsx             Remove
    aaa             Add
    bbb             Remove
    SQL>

  • Complex SQL help for a

    I do not know if this is the right place for thius type of post. If it is not please advise where the right place is.
    I need help generating a report, hopefully with SQL in 8.1.7
    SQL Statement which produced the data below the query :
    SELECT CHANGE.change_number, CHANGE.route_date as DATE_TO_CCB, nodetable.description AS Approver_required, (TRIM(BOTH ',' FROM CHANGE.PRODUCT_LINES)) AS PRODUCT_LINES /*, PROPERTYTABLE.VALUE as PRODUCT_LINES */
    FROM CHANGE, signoff, workflow_process, nodetable /*, PROPERTYTABLE */
    WHERE ( (CHANGE.ID = signoff.change_id)
    AND (CHANGE.process_id = signoff.process_id)
    AND ((nodetable.id = signoff.user_assigned) or (nodetable.id=signoff.user_signed))
    AND (CHANGE.process_id = workflow_process.ID)
    AND (CHANGE.ID = workflow_process.change_id)
    AND (CHANGE.workflow_id = workflow_process.workflow_id)
    AND (SIGNOFF.SIGNOFF_STATUS=0 )/* in (0, 2, 3)) */ /* 0=request needs attention, 2=request approved, 3=request rejected */
    AND (SIGNOFF.REQUIRED=5 or SIGNOFF.REQUIRED=1) /* 1=Approver 5= Ad Hoc Approver */
    AND (CHANGE.IN_REVIEW=1)
    AND (CHANGE.RELEASE_DATE IS NULL)
    AND (CHANGE.CLASS != '4928')
    /* AND (PROPERTYTABLE.PROPERTYID IN (SELECT TRIM(BOTH ',' FROM CHANGE.PRODUCT_LINES) FROM CHANGE)) */
    order by change.route_date desc
    **** Results **********
    CHANGE_NUMBER|DATE_TO_CCB|APPROVER_REQUIRED|PRODUCT_LINES
    C02190|11/14/2008 3:34:02 PM|Anurag Upadhyay|270354,270362|
    C02190|11/14/2008 3:34:02 PM|Dennis McGuire|270354,270362|
    C02190|11/14/2008 3:34:02 PM|Hamid Khazaei|270354,270362|
    C02190|11/14/2008 3:34:02 PM|Mandy York|270354,270362|
    C02193|11/14/2008 3:05:18 PM|Hamid Khazaei|274279,266339,266340,266341|
    C02193|11/14/2008 3:05:18 PM|Rob Brogle|274279,266339,266340,266341|
    C02193|11/14/2008 3:05:18 PM|Xavier Otazo|274279,266339,266340,266341|
    C02193|11/14/2008 3:05:18 PM|san|274279,266339,266340,266341|
    C02194|11/14/2008 2:51:34 PM|Diana Young|271503|
    C02194|11/14/2008 2:51:34 PM|Carl Krentz|271503|
    C02194|11/14/2008 2:51:34 PM|Dennis Yen|271503|
    C02194|11/14/2008 2:51:34 PM|Gordon Ries|271503|
    C02194|11/14/2008 2:51:34 PM|Sunil Khatana|271503|
    M00532|11/13/2008 1:34:42 PM|Dennis Yen|270356,270354,270360,274279,266339,266340,266341,276780,260784|
    M00532|11/13/2008 1:34:42 PM|Jin Hong|270356,270354,270360,274279,266339,266340,266341,276780,260784|
    M00532|11/13/2008 1:34:42 PM|Sunil Khatana|270356,270354,270360,274279,266339,266340,266341,276780,260784|
    Each value in the numeric comma delimited string has a corresponding ID for the actual test string value in another table as shown below.
    PROPERTYID|VALUE
    260775|product 1
    260776|Product 2
    260777|Product x
    260778|Product y
    260779|Internal
    260780|ORCA
    260781|Tiger
    260782|Orange product
    260783|Restricted
    260784|Product zz
    266259|Product YYY
    266260|Hercules
    266261|Tangerine
    *****Desired output****
    CHANGE_NUMBER|DATE_TO_CCB|APPROVER_REQUIRED|PRODUCT_LINES
    C02190|Nov/14/2008 03:34:02 PM|Anurag Upadhyay, Dennis McGuire, Hamid Khazaei, Mandy York|Product Y,Product 1
    C02193|Nov/14/2008 03:05:18 PM|Hamid Khazaei, Rob Brogle, Xavier Otazo, san|Hercules,Apple,Product 3,Product zz
    C02194|Nov/14/2008 02:51:34 PM|Diana Young, Carl Krentz, Dennis Yen, Gordon Ries, Sunil Khatana|Product 2
    M00532|Nov/13/2008 01:34:42 PM|Dennis Yen, Jin Hong, Sunil Khatana|Product 1,Product 4,product yy,product YYY,ORCA,Tiger,Orange product,Restricted

    Hi,
    Here's how you can do it in Oracle 8.1.
    To get the individual sub-strings from product_lines, join your current result set to this "counter table"
    (   SELECT  ROWNUM  AS n
        FROM    all_objects
        WHERE   ROWNUM <= 10 -- upper bound on number of items
    )  cntrIf you don't know the worst case of how many items might be in product_lines, it's a little more complicated:
    (   SELECT  ROWNUM  AS n
        FROM    all_objects
        WHERE   ROWNUM <= 1 +
                SELECT  MAX ( LENGTH (product_lines)
                            - LENGTH (REPLACE (product_lines, ','))
                FROM    table_name
    )  cntrJoin this to the existing result set like this
    WHERE   ...
    AND     INSTR ( product_lines || ','    -- one extra comma added
                  , 1
                  , n
                  ) > 0When you do the join, you will have
    one copy of all the rows with one item in producgt_lines,
    two copies of all the rows with two items in producgt_lines,
    three copies of all the rows with three items in producgt_lines,
    and so on.
    When a row has been copied, each copy will have a different value of cntr.n.
    To extract the n-th substring from product_lines:
    SELECT  ...
            SUBSTR ( product_lines
                   , INSTR ( ',' || product_lines,   ',',   1,   n)
                   , ( INSTR (product_lines || ',',   ',',   1,   n)
                     - INSTR (',' || product_lines,   ',',   1,   n)
                   )  AS product_lines_itemWhen you have derived this column, you can join to the table with the translations
    WHERE  TO_NUMBER (product_lines_item) = propertyidTo combine these rows into one row with a comma-delimited list, GROUP BY all the columns you want to select except the property_value ('produc 1', 'tangerine', etv.), and SELECT:
    LTRIM ( MAX (CASE WHEN n =  1 THEN ',' || property_value END) ||
            MAX (CASE WHEN n =  2 THEN ',' || property_value END) ||
            MAX (CASE WHEN n = 10 THEN ',' || property_value END)
          )I don't know a good way to re-combine the rows in Oracle 8 without assuming some limit on the number of items. I assumed there would never be more than 10 in the example above. You can say 20 or 100, I suppose, if you want to. If you guess too high, everything will still work: the query will just be slower.
    This is a just one example of why packing several values into a single column is a bad idea.

  • Pivot SQL --Pls advise

    Select distinct a.forename as "Name",
    a.surname as "Surname",
    a.forename ||''||a.surname as "Fullname",
    b.ancestors as "Ancestors",
    Other columns ..
    from table1 a,table2 b,table3 c,table4 d...
    where a.col1 =b.col1 and ..(other conditions)
    Output is as follows:
    Forename1 Surname1 Fullname1 Ancestor1 Other columns
    Forename1 Surname1 Fullname1 Ancestor2 Other columns
    Forename1 Surname1 Fullname1 Ancestor3 Other columns
    Forename1 Surname1 Fullname1 Ancestor4 Other columns
    required output is
    Forename1 Surname1 Fullname1 Ancestor1/Ancestor2/Ancestor3/Ancestor4 Other columns
    I am new to Pivot concept and never used it.
    Please help in modifying query.
    thanks in advance.

    The ability to generalise from the specific - in this case the ability to figure out a solution to your problem by examining a solution to someone else's similar problem - is vital in the world of IT.
    How about developing your skills in that area by searching the forum for PIVOT or rows+to+columns and see what you can come up with? Even if you can't quite figure it out, we'll be happy to help you over the finish line once you post your query. I suspect that SYS_CONNECT_BY_PATH is actually going to be worth investigating rather than pivot, given your description of the desired output.

  • SQL Help

    Please help ...
    Data Sample:
    A1 B1C1 D1
    01 A 06/30/2008 1
    01 B 06/10/2008 1
    01 C 06/09/2008 1
    01 D 06/09/2008 1
    02 A 06/20/2008 1
    02 C 06/20/2008 1
    03 A 06/20/2008 1
    04 A 06/10/2008 2
    04 B 06/10/2008 1
    04 C 06/09/2008 1
    04 C 06/09/2008 1
    Output Should be:
    01 A 06/30/2008 1
    02 A 06/20/2008 1
    02 C 06/20/2008 1
    03 A 06/20/2008 1
    04 A 06/10/2008 2
    Rules:
    - Top D1 should be selected.
    - If there are tie in D1 per A1, should be looking for C1 for the latest date
         - if there are tie for the D1 and C1 per A1 this data should be selected
         - if there are only one D1 which is the latest then inly 1 record will be selected.

    Hi,
    try this:
    SQL> with t as ( -- "sample data"
      2  select '01' a1, 'A' b1, to_date('06/30/2008','mm/dd/yyyy') c1, 1 d1 from dual union all
      3  select '01', 'B', to_date('06/10/2008','mm/dd/yyyy'), 1 from dual union all
      4  select '01', 'C' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual union all
      5  select '01', 'D' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual union all
      6  select '02', 'A' , to_date('06/20/2008','mm/dd/yyyy'), 1 from dual union all
      7  select '02', 'C' , to_date('06/20/2008','mm/dd/yyyy'), 1 from dual union all
      8  select '03', 'A' , to_date('06/20/2008','mm/dd/yyyy'), 1 from dual union all
      9  select '04', 'A' , to_date('06/10/2008','mm/dd/yyyy'), 2 from dual union all
    10  select '04', 'B' , to_date('06/10/2008','mm/dd/yyyy'), 1 from dual union all
    11  select '04', 'C' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual union all
    12  select '04', 'C' , to_date('06/09/2008','mm/dd/yyyy'), 1 from dual
    13  ) -- "end sample data"
    14  select a1, b1, c1, d1
    15    from (select a1, b1, c1, d1,
    16                 max(c1) over(partition by a1) mxc1,
    17                 max(d1) over(partition by a1) mxd1,
    18                 min(d1) over(partition by a1) mind1
    19            from t)
    20   where 1 = case when mind1 = mxd1 then
    21                  case when c1 = mxc1 then 1 end
    22                 else case when d1 = mxd1 then 1 end
    23                 end
    24  /
    A1 B1 C1                  D1
    01 A  6/30/2008            1
    02 A  6/20/2008            1
    02 C  6/20/2008            1
    03 A  6/20/2008            1
    04 A  6/10/2008            2

  • SQL help please. !!!!!!!!!!

    hi
    i need some help on the following problem. let's say i have a sql select that return the following rows
    ME
    EL
    EO
    FA
    these are 4 rows of data returned by executing "select column1 from myTable where somecondition = true". however, i need to display these results as follow
    MW,EL,EO,FA
    which is just one row and they are concatenated as one result. is there any way to modify the sql to do it? your help is much appreciated. thanks

    hi
    i need some help on the following problem. let's say i
    have a sql select that return the following rows
    ME
    EL
    EO
    FA
    these are 4 rows of data returned by executing "select
    column1 from myTable where somecondition = true".
    however, i need to display these results as follow
    MW,EL,EO,FA
    which is just one row and they are concatenated as one
    result. is there any way to modify the sql to do it?
    your help is much appreciated. thanksit would be easier if you ahead know how many rows you going to get...
    select
    "row1" = select blah from table where blah = '1',
    "row2" = select blah from table where blah = '2',
    "row3" = select blah from table where blah = '3',
    "row4" = select blah from table where blah = '4'
    from table
    make sure the sub select must return one record only...

  • SQL help: Selecting tickets with no open tasks

    Hi Gurus,
    I'm new to SQL. I need your help in a script where I need to fetch the tickets with no open tasks.
    Say, following is the Task table
    Table: Task
    | ticketid | taskid | taskstatus |
    | 1 | 1 | O |
    | 1 | 2 | O |
    | 1 | 3 | O |
    | 2 | 4 | C |
    | 2 | 5 | C |
    | 3 | 6 | C |
    | 3 | 7 | O |
    The query should return the ticketid(s) with all its taskstatus = 'C'.
    Any help would be highly appreciated.
    Thanks

    Hi Surya,
    Here's an Oracle style example (Sorry, I just can't do that ansi stuff)
    SQL> with ticket as (select 1 ticketid, 'C' reason from dual union all
                    select 2 ticketid, 'O' reason from dual union all
                    select 3 ticketid, 'O' reason from dual union all
                    select 4 ticketid, 'C' reason from dual)
    ,taskstatus as (select 1 taskstatusid, 'O' taskstatus from dual union all
                    select 2 taskstatusid, 'C' taskstatus from dual union all
                    select 3 taskstatusid, 'P' taskstatus from dual union all
                    select 4 taskstatusid, 'F' taskstatus from dual union all
                    select 5 taskstatusid, 'O' taskstatus from dual union all
                    select 6 taskstatusid, 'C' taskstatus from dual union all
                    select 7 taskstatusid, 'P' taskstatus from dual union all
                    select 8 taskstatusid, 'F' taskstatus from dual)
          ,task as (select 1 ticketid,  1 taskid, 2 taskstatusid from dual union all
                    select 1 ticketid,  2 taskid, 3 taskstatusid from dual union all
                    select 1 ticketid,  3 taskid, 4 taskstatusid from dual union all
                    select 1 ticketid,  4 taskid, 4 taskstatusid from dual union all
                    select 2 ticketid,  5 taskid, 1 taskstatusid from dual union all
                    select 2 ticketid,  6 taskid, 1 taskstatusid from dual union all
                    select 2 ticketid,  7 taskid, 1 taskstatusid from dual union all
                    select 3 ticketid,  8 taskid, 2 taskstatusid from dual union all
                    select 3 ticketid,  9 taskid, 2 taskstatusid from dual union all
                    select 3 ticketid, 10 taskid, 6 taskstatusid from dual union all
                    select 4 ticketid, 11 taskid, 2 taskstatusid from dual union all
                    select 4 ticketid, 12 taskid, 6 taskstatusid from dual union all
                    select 4 ticketid, 13 taskid, 4 taskstatusid from dual union all
                    select 4 ticketid, 14 taskid, 8 taskstatusid from dual)
    select a.ticketid, c.taskstatus
      from  task a, ticket b, taskstatus c
    where a.ticketid = b.ticketid
       and c.taskstatusid = a.taskstatusid
       and (c.taskstatus = 'C' or c.taskstatus = 'F')
       and b.reason = 'C'     
       and not exists (select null
                         from task a1, taskstatus c1
                        where a1.ticketid = a.ticketid
                          and c1.taskstatusid = a1.taskstatusid
                          and (c1.taskstatus = 'O' or c1.taskstatus = 'P'))
    order by 1,2
      TICKETID T
             4 C
             4 C
             4 F
             4 F
    4 rows selected.Please note, how I made test data, that way is much more helpful than your tables
    Regards
    Peter

  • SQL HELP , URGENT PLEASE

    Hi,
    I want some help in writing a SQL Query .Its besically a hierarchical query. Let me lay down the table structure first to explain my requirements better.
    PORP_TABLE(NODE_LEVEL int, WBS_ID int, WBS_NUMBER varchar(60), LFT int,RGT int)
    SELECT NODE_LEVEL, WBS_ID, LFT,RGT FROM PROPOSAL_WBS PW WHERE PROPOSAL_REV_ID = 7000
    (SAMPLE DATA)
    NODE WBS
    LEVEL WBS_ID NUMBER LFT RGT
    0 7055 ROOT 1 24
    1 7056 1 2 5
    1 7088 2 6 9
    2 7057 1.1 3 4
    2 7089 2.1 7 8
    2 7091 3.1 11 14
    2 7103 3.2 15 16
    2 7105 4.1 19 20
    1 7090 3 10 17
    3 7092 3.1.1 12 13
    1 7104 4 18 23
    2 7106 4.2 21 22
    ALLOCATION_DETAIL( WBS_ID int, COST_ID int, PERIOD Date, AMOUNT Float)
    sample data
    WBS_ID , COST_ID , PERIOD , AMOUNT
    7057 100 01-jan-2005 5000
    7057 100 01-feb-2005 2000
    7057 100 01-mar-2005 1000
    7057 100 01-apr-2005 6000
    7057 100 01-may-2005 3000
    7057 100 01-jun-2005 45000
    7106 100 01-mar-2005 8000
    7106 100 01-apr-2005 7000
    7106 100 01-may-2005 9000
    Now the PORP_TABLE has got the parents and childs. Only the leaf nodes in the hierarchy has the values stored in the ALLOCATION_DETAIL table. Now here is the scenario
    In the example 7055 is the root WBS . The Leaf WBS are the one with max extension in the wbs number ( in this case it is 1.1, 2.1, 3.1.1, 3.2, 4.1 and 4.2)
    Now the Starting period for each leaf node in the ALLOCATION_TABLE could be differrent . What that means is WBS 1.1 could start in Jan -2003 and WBS 3.1 Could be Jul-2005 . So the ending perios are also differrent for differrent WBS . Some can span 2 years some can 5 years.
    So how to write a query so it retrieves the value for all the Wbs starting from the MIN ( PERIOD ) upto the MAX(PERIOD), and it should roll up also. Now there is No connect by Prior or any analytic functions available for this . THIS NEEDS TO BE DONE ONLY THROUGH TRADITIONAL SQL STATEMENT . And NO DB FUNCTIONS CAN BE USED .
    Now if the WBS is a parent node then it should have the sum of all its child nodes for the COST category.
    SO THE RESULT SET SHOULD BRING LIKE THIS
    WBS_NUMBER, PERIOD_NUMER, COST_CATEGORY , AMOUNT
    ROOT
    1
    1.1
    2
    2.1
    3
    3.1
    3.1.1
    3.2
    4
    4.1
    4.2
    ......

    Hi,
    <br>Read String Aggregation Techniques</br>
    <br>HTH,</br>
    <br>Nicolas.</br>

  • SQL help. Identify changes on a field.

    Greetings!
    PS/SQL is not an option for me. I need help to use SQL, if possible for the following scenario.
    Oracle 10G.
    Table : JOB_DATA
    EMPLID, DATE_EFF, DEPTID, JOBCODE
    100, 11/1/2012, 34567, MNG
    100, 10/1/2012, 34567, SUP
    100, 9/1/2012, 28967, MNG
    100, 8/15/2012, 28967, SUP
    100,6/30/2012,15879, MNG
    I need to get the following records only, that is ,whenever changes in Department ID.
    100, 10/1/2012, 34567, SUP
    100, 8/15/2012, 28967, SUP
    100,6/30/2012,15879, MNG
    Thanks in advance.

    Hi Rama,
    Next time please post table structure and sample data.
    Please read SQL and PL/SQL FAQ
    Here another way to do it:
    WITH job_data AS
       SELECT 100 emplid, TO_DATE('11/1/2012', 'MM/DD/YYYY') date_eff, 34567 deptid, 'MNG' jobcode FROM DUAL UNION ALL
       SELECT 100 emplid, TO_DATE('10/1/2012', 'MM/DD/YYYY') date_eff, 34567 deptid, 'SUP' jobcode FROM DUAL UNION ALL
       SELECT 100 emplid, TO_DATE('9/1/2012' , 'MM/DD/YYYY') date_eff, 28967 deptid, 'MNG' jobcode FROM DUAL UNION ALL
       SELECT 100 emplid, TO_DATE('8/15/2012', 'MM/DD/YYYY') date_eff, 28967 deptid, 'SUP' jobcode FROM DUAL UNION ALL
       SELECT 100 emplid, TO_DATE('6/30/2012', 'MM/DD/YYYY') date_eff, 15879 deptid, 'MNG' jobcode FROM DUAL
    SELECT emplid, date_eff, deptid, jobcode
      FROM (SELECT j.*
                 , DENSE_RANK() OVER (PARTITION BY emplid, deptid ORDER BY date_eff) rn
             FROM job_data j
    WHERE rn = 1
    ORDER BY date_eff DESC;
        EMPLID DATE_EFF       DEPTID JOBCODE
           100 10/01/2012      34567 SUP   
           100 08/15/2012      28967 SUP   
           100 06/30/2012      15879 MNG   PARTITION BY emplid, deptid means that any time this combination of value is changing the rank will start again from 1.
    The rank is ordered by date_eff.
    I assume that you don't have the same date_eff for more than one record. If you have same date_eff for more than one record you need to explain what will be the logic in this case.
    Regards.
    Al
    Edited by: Alberto Faenza on Nov 15, 2012 8:50 PM
    Clarifications added

Maybe you are looking for

  • How to stream YouTube video in PDF document using ID 5.5?

    I'm using ID 5.5 and know how to insert a video into a document using the Media palette, "Insert video from URL" option. However, I need to stream a YouTube video in an interactive PDF document, and when I try to insert the link from YouTube into the

  • Having multiple threads in ios 8.1 with the same people in a group message.

    When I send an imessage out to a group, some of the group responses will come back through a different message with all the same people. This just means I have 3-4 different threads in my messages with all of the same people. It's also difficult to r

  • Create a Link between Work Order and Reapir Order

    IREAPIRORDER is the reapir order(IW54) AUFNR is the work order (IW31) w_relation = 'VONA'. fs_obj_rolea-objtype = 'BUS2032'. fs_obj_rolea-objkey = REAPIRORDER. fs_obj_roleb-objtype = 'BUS2007'. fs_obj_roleb-objkey = AUFNR. CALL FUNCTION 'BINARY_RELAT

  • Icon preview not working properly

    I have a folder with mp4 files, where they all have preview icons except one file. All the files were created and saved the same way and the folder in Leopard is set to show previews so I don't know why that 1 file should be any different. I've repai

  • KMANU field value download from R/3 to CRM for price Condition type

    Hi We done changes for KMANU field in R/3 - price condition type and that changes have to download from r/3 to CRM. I was tried below object adapters to update field value (R/3 u2013 table name: T685A - KMANU) from R/3 to CRM (Table :PRCC_COND_CT u20