Implementing Pivot Table like functionality using SQL

Dear All,
Please access a online document:
http://docs.google.com/View?docid=dhntd3vh_0gmwgmq
A 'query-output' is given.
I have pasted this output in Excel and using it's Pivot table feature
obtained an output given as 'Expected-Output' in the document.
How can I achieve this using SQL?
Any guidelines are most welcome.
-Sameer

See if this implementation could satisfy your needings.
     CREATE THE A TABLE WITH ESSENTIAL INFORMATION
CREATE TABLE THINGS (
     WHO     VARCHAR2(32) NOT NULL,
     WHAT VARCHAR2(32) NOT NULL,
     NUM NUMBER
     FILLING THE ESSENTIAL INFORMATION
INSERT INTO THINGS VALUES ('AFAS','TRANSACTION',4);
INSERT INTO THINGS VALUES ('FAS-AP','TRANSACTION',2);
INSERT INTO THINGS VALUES ('FAS-AR','TRANSACTION',2);               
INSERT INTO THINGS VALUES ('FAS-GL','MASTER',3);
INSERT INTO THINGS VALUES ('FAS-GL','REPORT',5);
INSERT INTO THINGS VALUES ('INTERNATIONAL CARGO','MASTER',1);
INSERT INTO THINGS VALUES ('INTERNATIONAL CARGO','REPORT',2);
INSERT INTO THINGS VALUES ('INTERNATIONAL CARGO','TRANSACTION',9);
INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','INTELLIVIEW REPORT',1);
INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','MASTER',4);
INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','TRANSACTION',76);
INSERT INTO THINGS VALUES ('PACKAGE EXPRESS','UTILITIES',1);
INSERT INTO THINGS VALUES ('WAREHOUSE','REPORT',1);
INSERT INTO THINGS VALUES ('WAREHOUSE','TRANSACTION',9);
     CREATE A TABLE FOR THE FULL CORRISPONDENCE
CREATE TABLE THINGS2 AS
     SELECT A.WHO,B.WHAT, 0 NUM
     FROM (
          SELECT DISTINCT WHO
          FROM THINGS
     ) A, (
          SELECT DISTINCT WHAT
          FROM THINGS
     )B;
     SET THE RIGHT VALUES ON EACH ROW
UPDATE THINGS2 A
SET NUM = (
     SELECT NVL(SUM(NUM),0)
     FROM THINGS B
     WHERE ( A.WHO = B.WHO )
          AND ( A.WHAT = B.WHAT )
     SHOW THE FULL TABLE ( FULL BECAUSE IT CONTAINS THE FULL JOIN BETWEEN "WHO" AND "WHAT" )
SELECT *
FROM THINGS2
     RETRIVE THE EXPECTED OUTPUT
SELECT A.WHO,"TRANSACTION","MASTER","INTELLIVIEW REPORT","UTILITIES"
FROM (
     SELECT WHO,NUM "TRANSACTION"
     FROM THINGS2
     WHERE WHAT = 'TRANSACTION'
) A,(
     SELECT WHO,NUM "MASTER"
     FROM THINGS2
     WHERE WHAT = 'MASTER'
     ) B,(
     SELECT WHO,NUM "REPORT"
     FROM THINGS2
     WHERE WHAT = 'REPORT'
     ) C,(
     SELECT WHO,NUM "INTELLIVIEW REPORT"
     FROM THINGS2
     WHERE WHAT = 'INTELLIVIEW REPORT'
     ) D,(
     SELECT WHO,NUM "UTILITIES"
     FROM THINGS2
     WHERE WHAT = 'UTILITIES'
     ) E
WHERE ( A.WHO = B.WHO )
     AND ( A.WHO = C.WHO )
     AND ( A.WHO = D.WHO )
     AND ( A.WHO = E.WHO );
Ps.
Could anybody tell me how is it possible to indent text on the board of this forum?
Bye Alessandro

Similar Messages

  • Pivot Table Like Functionality

    Hello,
    I want to create a pie chart from a list of customer transactions and have the pie chart display the top 5 customers by revenue.  In Excel I would use a pivot chart to consolidate and sum transactions based on the customer's name. 
    How can I do this in Project Siena?
    Thank you,
    Ted

    Hi Ayuba,
    I'm going to copy/paste a sample of the spreadsheet I've been working with.  Please excuse the formatting.
    What I'm starting with is a sample BI report that is a list of customer transactions.  As you can see different customer's buy different items on different days.  My goal is to create a pie chart that shows the total amount each customer has spent
    and not the individual transactions.
    This is very simple with pivot tablets in Excels because I can auto sum based on customer name.  With Pivot tablets I can create a pie chart with 4 slices (one for each customer), but by default the Siena pie chart makes 11 slices (one for each transaction). 
    So how can I create the pie chart with 4 slices and sum the Total Unit Cost for each customer?
    Vendor
    Customer
    Product
    Date
    Quantity
    Unit Cost
    Total Unit Cost
    Microsoft
    B3 Cycles
    Windows Server 2013
    10/1/2014
    88
    $196.78
    $17,316.64
    Airwatch
    Boeing General Dynamics
    Blue Bundle
    10/1/2014
    2000
    $36.23
    $72,460.00
    Vmware
    Boeing General Dynamics
    vSphere 5.1
    10/1/2014
    4
    $112.55
    $450.20
    Adobe
    Hilton Head Marketing
    Creative Suite
    10/2/2014
    5
    $223.15
    $1,115.75
    Adobe
    Hilton Head Marketing
    Creative Suite
    9/24/2014
    45
    $223.15
    $10,041.75
    Adobe
    Hilton Head Marketing
    Creative Suite
    9/24/2014
    2
    $223.15
    $446.30
    Adobe
    Hilton Head Marketing
    Creative Suite
    9/24/2014
    8
    $223.15
    $1,785.20
    Adobe
    Hilton Head Marketing
    Creative Suite
    9/24/2014
    7
    $223.15
    $1,562.05
    Adobe
    Hilton Head Marketing
    Creative Suite
    9/16/2014
    21
    $223.15
    $4,686.15
    Adobe
    Hilton Head Marketing
    Creative Suite
    5/22/2014
    35
    $223.15
    $7,810.25
    Microsoft
    Clown College Inc.
    Office 2013
    5/18/2014
    4
    $69.78
    $279.12

  • How to implement Excel like functionality using Table?

    I have a requirement to implement excel like functionality in a table, i.e when I update the amount in the first row and tab out, the values in the rows below should get affected.
    Could any one suggest idea how to get this done?

    Hi Timo,
    Thanks for your Reply.
    Can you please provide the code for capturing the key stroke in java script and queue it in the server and calling only the adf data table values from it.
    Thanks And Regards,
    Lovenish Garg
    Edited by: lovenish on 21-Jan-2011 04:25

  • Demonstrating PL/SQL Functions Using SQL Developer

    Good afternoon,
    I'm starting to write some PL/SQL functions to replace some of the SQL that I use most frequently.  A couple of very simple examples would be:
    create or replace function func_test (p_1 number) return number
    is
    x number;
    y number;
    begin
    x :=1;
    y :=2;
    return p_1 * x * y;
    end func_test;
    create or replace function func_test2 (p_1 varchar2) return varchar2
    is
    return_val varchar2(10);
    begin
    select p_1 into return_val from dual;
    return return_val;
    end func_test2;
    However, at my workplace I haven't been granted create function privileges yet until I can demonstrate some examples, which is understandable.
    For the time being, without these privileges, is there a way I can build/test functions in principle locally using SQL Developer without the need to write the functions to our database? I.e. can I demonstrate the above in SQL Developer, but without wrapping in create or replace syntax?
    I hope this isn't too vague.
    Using Oracle 11gR2 (not logged in to workplace database at the moment for specific version no.)
    SQL Developer 3.4
    Thanks,
    TP

    sb92075 02-Nov-2013 19:12 (in response to TinyPenguin)
    populating test DB with data is a solvable problem.
    You don't need client data to test code (functions).
    You only need sample test data; which generally is less than a few dozen records per table.
    Absolutely, of course. Our client database is pretty messy though, and includes data prior to the implementation of more recent business rules that I need to take account of. Useful perspective though, thanks.
    rp0428 02-Nov-2013 19:14 (in response to TinyPenguin)
    Sure, but then I wouldn't have access to all the data in our client database to test functions under various circumstances.
    Huh? Why not? It's your database so what keeps you from creating a database link to your client database where all the data is?
    Also, I suppose it's not good practice to constantly write/replace/drop functions to/from a database when developing them? Better to test the function in principle and then write to the database?
    Huh? Why not? What you think a dev database is for if not for development?
    Based on your two posts so far in this thread it's understandable why they don't want to give you privileges yet. Those sample 'functions' you posted are NOT a good use for functions.
    In sql developer you can just create and save the queries you use most often. There is no need to create functions for that.
    But if you do need an anonymous function now and then just create one using sql*plus syntax:
    Our IT department are pretty sensitive about how they allow access, even to the dev environment. As you've identified, I'm not naturally a programmer so the option to play around with the data to develop some representative examples about how we can simplify and devolve SQL reporting to more members of staff is useful to me. I just wrote those two function quickly for the purpose of posting some sample data, which I thought would be helpful. Thanks for illustrating how to return their output using an anonymous block.
    FrankKulash 02-Nov-2013 19:13 (in response to TinyPenguin)
    Hi,
    The obvious solution is to get the privileges.  If your employer really wants you to do something, they need to give you the necessary privileges to do it.  It's silly for them to tell you to do something, but refuse to let you do it.
    Failing that, you can install Oracle on your own machine, as suggested above.  It's free and legitimate if you're only using it for learning and developing.  Oracle Express Edition is very easy to install.
    As a last resort, you can write functions and procedures that are local to an anonymous block, like this:
    Thanks Frank. Yeah I'm going to speak with our DBA next week about privileges. I've got XE/SQL Developer installed on my own computer - I wrote those sample functions using them - I just wasn't sure how to call/return anonymous blocks as both you and rp identified to develop at work as an interim solution.
    Thanks a lot All,
    TP.

  • One question in measures table heading of a pivot table view when using 11g

    Hi experts,
    I have been working on OBIEE 10g for 2 years, and lately I started developing on OBIEE 11g. It is great to discover so many new features which make reporting so much easier and look better, meanwhile, I got confused by some detail changes they have made. I was able to overcome most of the difficulties I have met with, but now there is *1* I can not figure out. Any idea or suggestion is appreciated.
    In OBIEE 10g, when we develop a report using a pivot table, we put column A and B in Rows aera and column C Measures aera, the result would look like this:
    / / A / / B / / C / /
    //VA1 //VB1// VC1//
    //VA1// VB1 //VC1//
    But now I am using 11g, when I put these columns in the same aeres as I did in 10g, the result is surprising like this:
    / / BLANK / / C / /
    / / A / / B / / blank //
    //VA1 //VB1/|/ VC1//
    //VA1/|/VB1 // VC1//
    It looks weird that it should put Rows labels and Measure labels in different lines and create blank labels, and barely makes any sense. I am OK with the blank above the Row labels, but not with the blank below the measure label. A blank label that separates a label and its value is not what I want.
    Can anyone help me to make the pivot table look the same as it does in 10g? Or at least remove the blank label below the Measure label?
    Thanks in advance.

    Hi,
    I am facing the same issue, have you solved it?

  • Create Pivot Table in Background using a Batch Job

    I'm using 4.7 and I have a request to create a daily batch job that will run an ALV report and create a pivot table. How do I create the pivot table? I tried using the FM 'EXCEL_OLE_STANDARD_DAT' but I get a 'File do not exist' message. Tried looking at the documentaion of this fm but it doesn't have any. If anybody can explain to me how this function works, that would really be great. Or if you have a better solution, that would be even greater than great.
    Thanks in advance!

    Hello Liz,
    I think it is not possible because to generate an Excel file, SAP needs the Excel program.
    But when the program is executed in backgroud, SAP server does not have a way to access Excel program to generate the file.
    Hope I am wrong...
    Regards,
    Mauricio

  • I try to find such as pivot table like in excel sheet

    How to collect data like pivot table in excel sheet. Please help me

    Hi Chepot,
    Welcome to Apple Discussions and the Numbers '09 forum.
    Numbers does not support pivot tables, but there may be a way to accomplish what you want.
    Here's a link to search results for 'pivot AND table' in the Numbers '09 forum during the past year. Check these prior discussions. If they don't answer your question, post a reply here with further details on the arrangement of data you want to collect.
    Regards,
    Barry

  • Pivot Tables in Website using Excel Web App

    I have an Excel file on OneDrive that has 3 tabs.  The 1st tab has an area where the user inputs information (numbers).  These numbers flow into the 2nd tab and update cells based on the formulas.  The 3rd tab has Pivot Tables based on the
    2nd tab master data. 
    I embedded the 1st tab into my website, so the user can inputs information.  I then embedded the pivot tables in my website.  The problem is that the information in the pivot tables are not updating based on the information the user puts in. 
    When I right click and hit "refresh", it still does not update.  Any ideas?

     When you embed the 1st tab on the webpage, and then change the value ,It will not affect the data of the original workbook which saved on the OneDrive. So the PivotTable data will not updated. You can see:
    You need to embed all of these 3 tabs on your workbook on the webpage, then change the value of 1st tab, back to the PivotTable, click refresh, the pivot table data will updated as expected.
    Wind Zhang
    TechNet Community Support

  • How to track, who are using the particular table in oracle using sql or pl/

    we have database DB1 and it contains schema s1 and the schema s1 contains all the user defined objects including tables and others and it contains one of the table name called t1. we have users u1, u1, u2...uN.
    Now, I want to track who are all using that particular table t1 under schema s1 (track user, time).
    How to do this from sql OR pl/sql

    hi,
    Thanks for the url , it was useful but i am unable to extract anything from it , For ex i gave a command like this
    Audit Select, Insert, Delete
    On tk_sales_master
    By Access
    Whenever Successful;
    then
    Select * From tk_sales_master
    Then
    Select SESSIONID, ENTRYID, Statement, Timestamp#, USERID From SYS.AUD$
    But i didnt get any rows from the SYS.AUD$
    Can u pull me out
    with warm regards
    ssr

  • How to create a table-like layout using Iterator?

    I want to render several items in a table format using an iterator. Can anyone guide me on how to line up the different columns, like in a table?
    I cannot use the built in table because I want to change the display later using javascript and the af:table component does not work with that.
    The table will be in a panelsplitter element. The code I have right now:
    <af:iterator id="i1"
                       value="#{bindings.DenormPlanLine1.collectionModel}"
                       var="row"
                       rows="#{bindings.DenormPlanLine1.rangeSize}">
                        <af:panelGroupLayout id="pg1" layout="horizontal"
                                             inlineStyle="width:800.0px;">
                          <f:facet name="separator">
                            <af:spacer width="5" height="1" />
                          </f:facet>
                          <af:outputText value="#{row.StartDate}"  styleClass="sDate"/>
                          <af:outputText value="#{row.FinishDate}" styleClass="fDate"/>
                          <af:outputText value="#{row.DenormWbsLevel}" styleClass="level"/>
                          <af:outputText value="#{row.DisplaySequence}" styleClass="dSequence"/>
                          <af:outputText value="#{row.ElementVersionId}" styleClass="elVersionId"/>
                          <af:outputText value="#{row.TaskType}" styleClass="taskType"/>
                          <af:outputText value="#{row.PercentComplete/100}" styleClass="percent">
                            <af:convertNumber type="percent" />
                          </af:outputText>
                        </af:panelGroupLayout>
                        <af:spacer width="100%" />
                        </af:iterator>

    User, please tell us your Jdev version!
    Check out this sample http://andrejusb.blogspot.de/2011/05/oracle-adf-11g-custom-table-pagination.html
    Timo

  • Function using "sql in" in select

    hi all...
    I need a function that takes in a param that is a string of employee types. I can't figure out how to pass the comma delineated string to the function. something like "Manager","Director","Analyst".
    CREATE or REPLACE....
    FUNCTION findEmployeesByType(a_employee_types VARCHAR2) return reportref_type
    IS
    return_cur reportref_type;
    l_sql varchar2(4000) :=
    'select last_name, first_name, ssn
    from employee
    where employee_type in (:p_employee_types)'
    END packageName;
    the same query would be:
    select last_name, first_name, ssn
    from employee
    where employee_type in ("Manager","Director","Analyst")
    thanks..

    thanks for the help. I doing this inside a package. I created the type outside the package declaration...
    CREATE OR REPLACE TYPE mytabletype IS TABLE OF VARCHAR2 (255);
    Then I created a new function within the package:
    FUNCTION getList(p_string VARCHAR2) RETURN mytabletype;
    When I try to call getList from another function, I'm getting an 'Invalid Identifier' for the string that's passed in.
    Here's my function definition:
    FUNCTION getPendingPmtsByTrial (a_trial_id NUMBER,
    a_trialparty_id NUMBER DEFAULT NULL,
    a_partyroles VARCHAR2 DEFAULT NULL) RETURN reportref_type
    Then I make the call to the getList function as follows:
    AND trialparty.partyrole_code IN (select cast (report.getList(a_partyroles) as mytabletype) from dual)
    ideas ?...thanks
    here's my getList function:
    FUNCTION getList ( p_string IN VARCHAR2 ) RETURN mytabletype
    IS
    l_string LONG DEFAULT p_string || ',';
    l_data mytabletype := mytabletype();
    n NUMBER;
    BEGIN
    LOOP
    EXIT WHEN l_string IS NULL;
    n := INSTR(l_string, ',');
    l_data.EXTEND;
    l_data(l_data.COUNT) := TRIM(SUBSTR(l_string, 1, n-1));
    l_string := SUBSTR(l_string, n + 1);
    END LOOP;
    RETURN l_data;
    END;

  • How to Exclude table like %AUDIT% using the Datapump API

    Hello,
    I am trying to use the datapump API to import table across a database link excluding table with a name like %AUDIT%. I have it all working except the table execution. I am using Oracle 11.1.0.6.

    this works in my app
    in DB R11.2
    in job_mode = 'TABLE'
              dbms_datapump.metadata_filter (
              handle          =>     job_handle,
              name          =>     'NAME_EXPR',
              value          =>     'NOT IN (''TABLENAME_1'', ''TABLENAME_2'' , ''TABLE_NAME_3'' )'
    try this works for you
              dbms_datapump.metadata_filter (
              handle          =>     job_handle,
              name          =>     'NAME_EXPR',
              value      => 'NOT LIKE ''%AUDIT%'''
    Edited by: astramare on Jul 7, 2011 2:57 PM

  • How to perform Excel like function in Sql

    TABLE_NAM             ROWS_IMPACTED_ACTUAL            OPERATION_TIMESTAMP                              TIME_ELASPED
    END_OF_DAY       0                         06-SEP-12 04.37.18.328927000 PM     
    TAXL                           0                         06-SEP-12 04.37.18.337675000 PM     
    TRANSACTION      0                         06-SEP-12 04.37.18.430409000 PM     
    PORTFOLIO       0                          06-SEP-12 04.37.18.430984000 PM     
    I have a table similar to the one above, how do i get time elasped above , for each operation?
    That is how long each table completed an operation.
    Thanks
    Edited by: user8375449 on Sep 14, 2012 4:09 AM

    No, you cannot attach documents/picture to the forums, that's just not possible (this isn't Oracle Support which you pay for)
    If you read the FAQ that I linked to, it tells you how to post code and data using the {noformat}{noformat} tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to disable Row label from the aggregation function in Pivot table

    Hello everyone,
    I have table in Power Pivot like shown below:
    Item_Name
    Category
    Vendor
    Sales_Amount
    Item 1
    Category 1
    Vendor 1
    30
    Item 2
    Category 1
    Vendor 2
    25
    Item 3
    Category 2
    Vendor 3
    50
    Item 3
    Category 2
    Vendor 3
    60
    Item 3
    Category 2
    Vendor 3
    20
    Item 2
    Category 1
    Vendor 2
    10
    Item 2
    Category 1
    Vendor 2
    30
    Item 2
    Category 1
    Vendor 2
    100
    Item 2
    Category 1
    Vendor 1
    20
    By using above table i have to create Rank(Based on Sales amount) by Category and Item name in Pivot table, i have done easily like added two dimension attribute(Category, Item_Name) into row label and Sales_Amount into aggregation tab then I calculated
    rank:=RANKX(ALL(Sales[Item_Name]),[Sum of Sales_Amount]) so finally pivot table looks like shown below:
    But end user want to see the vendor name also in the pivot table but the Rank suppose to be based on Sales amount by Category and Item name. if i added the vendor name also into the row label, rank calculated based on on Sales amount by Category, Item
    name and vendor.
    I would be really grateful if anyone advise how to fix this problem as it will be helpful my most of the reports.
    Regards,
    Robert 

    Darren Gosbell,
    Thanks for your reply.
    Item_Name
    Category
    Vendor
    Sales_Amount
    Item 1
    Category 1
    Vendor 1
    30
    Item 2
    Category 1
    Vendor 2
    25
    Item 3
    Category 2
    Vendor 3
    50
    Item 3
    Category 2
    Vendor 3
    60
    Item 3
    Category 2
    Vendor 3
    20
    Item 2
    Category 1
    Vendor 2
    10
    Item 2
    Category 1
    Vendor 2
    30
    Item 2
    Category 1
    Vendor 2
    100
    Item 2
    Category 1
    Vendor 2
    20
    Item 4
    Category 1
    Vendor 2
    3
    Item 4
    Category 1
    Vendor 2
    50
    Item 4
    Category 1
    Vendor 2
    3
    The above is my new source data.
    I used this function to calculate  Rank:=RANKX(ALL(Sales[Item_Name]),[Sum of Sales_Amount])
    and also used yours below:  
    Rank2:=RANKX(SUMMARIZE(ALL(Sales),[Item_Name],[Category]),CALCULATE([Sum of Sales_Amount],ALLEXCEPT(Sales,Sales[Item_Name],Sales[Category])))
    The Preceding screenshot is the result of our two function but i wanna pivot table like shown below:
    Could please help me to fix it out.

  • SQL report region source to call a pl/sql function using DB link

    Hi - I have a pl/sql function fn_dbtype(id NUMBER) defined in database X. The pl/sql function executes couple DML statements and returns a string (a SELECT query). I am able to call this function using SQL Plus (Connected to Database X) as below and it works fine:
    declare
    vSQL VARCHAR2(100);
    begin
    vSQL := fn_dbtype(1);
    end;
    The DML operations completed fine and vSQL contains the "Select" query now.
    In APEX:
    I am trying to create a SQL report in APEX using SQL query(PL/SQL function returning a sql statement) option. I am trying to figure out what to put in the region source so that the output of the "Select" query is displayed in the report.
    Moreover APEX is hosted in a different database instance. So I would need to call this pl/sql function using a DB Link.
    Please let me know what I need to put in the region source to execute the pl/sql function which returns the "Select" query thereby displaying the query output in the report. Thanks.
    Edited by: user709584 on Mar 19, 2009 2:32 PM
    Edited by: user709584 on Mar 19, 2009 2:34 PM

    try something like this:
    return fn_dbtype(1)@dblink;

Maybe you are looking for

  • ITunes no longer recognizes my iPhone 4

    I have had 3 iOS devices connecting to iTunes on Windows for more than 4 months.  For some reason iTunes no longer recognizes my iPhone 4.  My iPad and iPhone 4S still work as they should.  Windows sees the iPhone 4, but it never shows up in iTunes. 

  • How can I email a pages 08 document that doesn't have to be opened  as an attachment by the recipient??   PS- I am using at&t mail.

    How can I email a document created on Pages '08 that doesn't have to be opened as an attachment by the recipients???? (I am using AT&T email)

  • Error Loading Data

    Error 1 when loading external data Message no. RSAR234 Diagonosis: Error number 1 occured when loading external data 1)Error when reading the file(access rights, file name...) 2)Error when generating the IDOC Can anyone tell what the error is regardi

  • Java Proxy Code Sample

    Hello SAP community. Does anyone have a step-by-step code sample for creating either a jsp or web dynpro application in Netweaver to use a java proxy to connect to XI that will calls a RFC or BAPI in SAP R3?

  • Time machine keeps OSX from updating to Mavericks - how do I fix?

    Keep trying to update my old computer to Mavericks. It's currently at 10.6.8 and totally updated. Everytime I go to install Mavericks, when it gets to the window where you choose where to save it, I try to pick my Hard Drive but I get an error messag