How to show data in a matrix form from a table using SQL

Dear Friends,
I have a table with three columns with the following data:
Market, Product, Date, Value
Market-A Product-A 01/01/04 34
Market-A Product-A 01/02/04 33
Market-A Product-A 01/03/04 67
Market-A Product-A 01/04/04 64
Market-A Product-B 01/01/04 34
Market-A Product-B 01/02/04 36
Market-A Product-B 01/03/04 77
Market-A Product-B 01/04/04 32
Market-B Product-C 01/01/04 25
Market-B Product-C 01/02/04 56
Market-B Product-C 01/03/04 45
Market-B Product-C 01/04/04 68
Market-B Product-D 01/01/04 78
Market-B Product-D 01/02/04 75
Market-B Product-D 01/03/04 32
Market-B Product-D 01/04/04 35
I have a requirement where in I have to filter the products based on market and then show in the following format on the screen:
After filtering based on Market-A (eg) the data should look like:
01/01/04 01/02/04 01/03/04 01/04/04
Product-A 34 33 67 64
Product-B 34 36 77 32
Kinldy suggest how can I write a query to get the data in this format using SQL
Thanks & Regards,
Vinay

scott@ORA92> -- test data:
scott@ORA92> SELECT * FROM a_table
  2  /
Market-A Product-A 01/01/04         34
Market-A Product-A 01/02/04         33
Market-A Product-A 01/03/04         67
Market-A Product-A 01/04/04         64
Market-A Product-B 01/01/04         34
Market-A Product-B 01/02/04         36
Market-A Product-B 01/03/04         77
Market-A Product-B 01/04/04         32
Market-B Product-C 01/01/04         25
Market-B Product-C 01/02/04         56
Market-B Product-C 01/03/04         45
Market-B Product-C 01/04/04         68
Market-B Product-D 01/01/04         78
Market-B Product-D 01/02/04         75
Market-B Product-D 01/03/04         32
Market-B Product-D 01/04/04         35
scott@ORA92> -- query:
scott@ORA92> SELECT product,
  2           SUM (DECODE (the_date, to_date ('01/01/2004', 'mm/dd/yyyy'), value)) AS "01/01/04",
  3           SUM (DECODE (the_date, to_date ('01/02/2004', 'mm/dd/yyyy'), value)) AS "01/02/04",
  4           SUM (DECODE (the_date, to_date ('01/03/2004', 'mm/dd/yyyy'), value)) AS "01/03/04",
  5           SUM (DECODE (the_date, to_date ('01/04/2004', 'mm/dd/yyyy'), value)) AS "01/04/04"
  6  FROM   a_table
  7  WHERE  market = 'Market-A'
  8  GROUP  BY product
  9  /
Product-A         34         33         67         64
Product-B         34         36         77         32
scott@ORA92>

Similar Messages

  • How to retrive the blob data from a table using sql query

    Hi gurus,
    I have a table which has " BLOB "content in a column .I want to view the data From BLOB column using sql query .It would be helpfull If some one share their idea.
    Regards,
    vardhani.

    You can use data templates.
    See this: http://blogs.oracle.com/xmlpublisher/entry/blob_clob_raw_and_looooong
    http://blogs.oracle.com/xmlpublisher/entry/inserting_blobs_into_your_repo
    Thanks,
    Bipuser

  • How do I add more than one column to a table using SQL?

    Hi
    I need to add 3 columns to a table using SQL
    the syntax
    "ALTER TABLE TEST ADD COLUMN newcol1 float";
    works fine - for adding one coumn only.
    For multiple columns I tried various permutations along the lines of
    "ALTER TABLE TEST ADD (COLUMN newcol01 float, COLUMN new2 float,COLUMN new3 float)";
    "ALTER TABLE TIPSTEST ADD COLUMN new1 float"
    "ALTER TABLE TIPSTEST ADD COLUMN new2 float"
    "ALTER TABLE TIPSTEST ADD COLUMN new3 float"
    etc., but this doesn't work.
    From a web search it sounds like SQL can only add one column at a time.
    I have a workaround : create intermediate temporary tables , copying data and adding
    one column at each stage. It seems a fairly awkward way of programming though.
    Am I missing something simple : is there a way to add multiple columns in one go?
    Thanks

    OK : solved an underlying problem with this one myself
    for the code
    String createString;
    createString =  "select COFFEES.* INTO NEWCOFFEES FROM COFFEES"; // example
              Statement stmt;
              try {
                   stmt = a_Globals.database1Connection.createStatement();
                          stmt.executeUpdate(createString);
                   stmt.close();
                   a_Globals.database1Connection.close();
              } catch(SQLException ex) {
                   System.err.println("SQLException: " + ex.getMessage());
              }                    commenting out the line:
    a_Globals.database1Connection.close();
    Allowed the subsequent SQL statement(s) to work OK. Looks like this was the cause of several
    difficulties, preventing me doing several SQL instructions in turn.
    Thanks for the responses.
    Mike2z

  • How can I remove the "Show Data in Single Pane" button from ui:table?

    All I have is paginate selected in table properties.

    Hi,
    Thank you for explaining it so clearly. After enabling the pagination, go to the properties sheet for the table. Under the Appearance section there is a property called paginateButton. Uncheck this property and you will have pagination enabled but not the Show data in a single pane button.
    Cheers
    Giri

  • How to pass data accpeted in the form of a Table to the Servlet.

    Hi guys. here is the problem:
    A page is displayed and it contains a table with about 20 rows and 2 columns. Each cell of the Table contains a TextField. The user has to enter data into these TextFields.
    How to i pass this 20 X 2 data to a servlet.
    Adding to the trouble.. the number of rows is not fixed. and depends on how many rows of data the user wishes to enter.
    A common example would be the line items in an ordering system.
    Any ideas guys??
    Thanks in advance

    Or give all the textfields the same name.
    <form>
    <input type="text" name="tfvalue">
    <input type="text" name="tfvalue">
    <input type="text" name="tfvalue">
    </form>Then in your servlet:
    String[] vals = request.getParameterValues("tfvalue");
    for(int i = 0; i < vals.length; i++){
      String tfvalue = vals;
    // do something with the value from textfield i
    edit:
    now that I think about it, I'm not sure if the value of an empty text field is submitted...

  • How to show a row has been "removed" from a table

    We maintain rows in a table with a version number which will determine the current set of accounts for a version. I need to be able to show the changes between the versions - when a row was ADDED, REMOVED or there was NO CHANGE. I can work out ADDED and NO_CHANGE without any problem, but I'm not sure how I can determine that a row has been REMOVED when it no longer exists in the next version.
    I have provided an example piece of SQL below:
    with w_acct1 as
    (select 'A1' acct, 0 vers from dual
    union all
    select 'A2' acct, 0 vers from dual
    union all
    select 'A3' acct, 0 vers from dual
    union all
    select 'A1' acct, 1 vers from dual
    union all
    select 'A2' acct, 1 vers from dual
    union all
    select 'A1' acct, 2 vers from dual
    union all
    select 'A4' acct, 2 vers from dual)
    select a.*,
           nvl(lead(acct) over (partition by acct order by vers desc),'NULL') ld,
           case when lead(acct) over (partition by acct order by vers desc) is null then
                   'ADDED'
               when lead(acct) over (partition by acct order by vers desc) = acct then
                   'NO_CHANGE'
               else
                   'REMOVED'
               end add_remove
    from w_acct1 a
    order by vers,acctWhich gives me the following result:
    ACCT VERS LD ADD_REMOVE
    A1     0     NULL     NEW
    A2     0     NULL     NEW
    A3     0     NULL     NEW
    A1     1     A1     NO_CHANGE
    A2     1     A2     NO_CHANGE
    A1     2     A1     NO_CHANGE
    A4     2     NULL     NEW
    The result I want is:
    ACCT VERS LD ADD_REMOVE
    A1     0     NULL     NEW
    A2     0     NULL     NEW
    A3     0     NULL     NEW
    A1     1     A1     NO_CHANGE
    A2     1     A2     NO_CHANGE
    A3     1     NULL     REMOVED
    A1     2     A1     NO_CHANGE
    A2     2     NULL     REMOVED
    A4     2     NULL     NEW
    Note the REMOVED rows associated with the version even though they don't exist in the dataset for that version number.
    Can this be done with analytic functions or some other cool Oracle feature I'm missing?
    Regards
    Richard

    You can't know about a row being removed unless you have a record of that row somewhere, either as a copy of your old data (see example below) or you've recorded the information using delete triggers etc.
    SQL> ed
    Wrote file afiedt.buf
      1  with old_data as (select 1 as id, 'A' as dta from dual union all
      2                     select 2, 'B' from dual union all
      3                     select 3, 'C' from dual)
      4      ,new_data as (select 1 as id, 'A' as dta from dual union all
      5                    select 3, 'X' from dual union all
      6                    select 4, 'Y' from dual)
      7  --
      8      ,ins_upd as (select * from new_data minus select * from old_data)
      9      ,del_upd as (select * from old_data minus select * from new_data)
    10      ,upd as (select id from ins_upd intersect select id from del_upd)
    11      ,ins as (select id from ins_upd minus select id from upd)
    12      ,del as (select id from del_upd minus select id from upd)
    13  --
    14  select 'Inserted' as action, null as old_id, null as old_dta, new_data.id as new_id, new_data.dta as new_dta
    15  from new_data join ins on (ins.id = new_data.id)
    16  union all
    17  select 'Updated', old_data.id, old_data.dta, new_data.id, new_data.dta
    18  from old_data join new_data on (old_data.id = new_data.id)
    19                join upd on (upd.id = new_data.id)
    20  union all
    21  select 'Deleted', old_data.id as old_id, old_data.dta as old_dta, null as new_id, null as new_dta
    22  from old_data join del on (del.id = old_data.id)
    23  union all
    24  select 'No Change' as action, new_data.id as old_id, new_data.dta as old_dta, new_data.id as new_id, new_data.dta as new_dta
    25  from new_data where id not in (select id from ins_upd union all
    26*                                select id from del_upd)
    SQL> /
    ACTION        OLD_ID O     NEW_ID N
    Inserted                        4 Y
    Updated            3 C          3 X
    Deleted            2 B
    No Change          1 A          1 A
    SQL>

  • How to show data vertical in ALV

    How to show data vertical in ALV?
    such as :
    [http://img402.imageshack.us/img402/9978/20101230215621.png|http://img402.imageshack.us/img402/9978/20101230215621.png]
    Moderator Message: Search for available information. Keywords - Dynamic Internal Table
    Edited by: kishan P on Dec 30, 2010 7:35 PM

    Transpose the contents of your internal table.
    Original:
    A 1 1 1
    B 2 2 2
    Transposed:
    A B
    1 2
    1 2
    1 2

  • How to Show BI report in adf form ?

    How to show bi Report in adf form ?
    (i dont show dashboard in adf form

    Hi,
    check this : http://husaindalal.blogspot.com/2009/11/integrating-bi-publisher-standalone.html
    there are some other helpful links as well:
    http://brendenanstey.blogspot.com/2007/01/adf-faces-and-xml-publisher-success.html
    http://technology.amis.nl/blog/2296/building-a-report-in-xml-publisher
    http://technology.amis.nl/blog/1597/xml-publisher-display-input-parameter-sqllims
    ~Abhijit

  • How to show image in a Transperent form ?? screen shots attached

    Hi
    Help me in making Images appearing as Transperent . Screen shots attached
    I am having a TextInput and a Search Button (The Functionality is that user can enter something in this TextInput and makes a Search Operation by pressing Search Button .)
    At the Initail screen display i need to show Some Image in transperent  Inside this TextInput  , when Mouse is focused on this TextInput , the Image will be completely Invisible .
    Now the question i want to ask is , how to show image in a Transperent form ??
    Please find the screen shots attached with this Thread .

    Thanks for specifying  the alpha property of an Image .

  • How to Insert date in 'DD/MM/YYYY' format in oracle using stored procedure?

    Hi
    How to Insert date in 'DD/MM/YYYY' format in oracle using stored procedure?
    This is my Input data.
    11/25/2007.
    By using below query, it is inserted into database.
    sql>Insert into tblname values(to_date('11/25/2007','MM/DD/YYYY'));
    But using stored procedure, the same query is not running.
    It shows error like
    ORA-01843: not a valid month ORA-06512: at line 1
    Procedure:
    create or replace procedure Date_Test(datejoin in DATE) is
    begin
    insert into datetest values(to_date(datejoin,'MM/DD/YYYY'));
    end Date_Test;
    I had used 'nls_date_language = american' also.
    Prcodeure is created but not worked in jsp. The same error is thrown.
    Pls provide a solution

    This might help you....
    SQL> Create Table DateTest(col1 Date);
    Table created.
    Elapsed: 00:00:00.00
    SQL> create or replace procedure Date_Test(datejoin in DATE) is
    2 begin
    3 insert into datetest values(to_date(datejoin,'MM/DD/YYYY'));
    4 end ;
    5 /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec Date_Test('11/25/2007');
    BEGIN Date_Test('11/25/2007'); END;
    ERROR at line 1:
    ORA-01843: not a valid month
    ORA-06512: at line 1
    Elapsed: 00:00:00.00
    SQL> exec Date_Test(To_Date('11/25/2007','mm/dd/yyyy'));
    BEGIN Date_Test(To_Date('11/25/2007','mm/dd/yyyy')); END;
    ERROR at line 1:
    ORA-01843: not a valid month
    ORA-06512: at "CTBATCH.DATE_TEST", line 3
    ORA-06512: at line 1
    Elapsed: 00:00:00.00
    SQL> create or replace procedure Date_Test(datejoin in DATE) is
    2 begin
    3 insert into datetest values(datejoin);
    4 end ;
    5 /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec Date_Test(To_Date('11/25/2007','mm/dd/yyyy'));
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> Select * from DateTest;
    COL1
    25-NOV-07
    Elapsed: 00:00:00.00
    SQL> create or replace procedure Date_Test(datejoin in VarChar2) is
    2 begin
    3 insert into datetest values(to_date(datejoin,'mm/dd/yyyy'));
    4 end ;
    5 /
    Procedure created.
    Elapsed: 00:00:00.00
    SQL> exec Date_Test('11/25/2007');
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> select * from DateTest;
    COL1
    25-NOV-07
    25-NOV-07
    Elapsed: 00:00:00.00
    SQL>

  • How to process data in the past based from data in the present

    hello guys,
    i have a problem in my labview programs. how to process data in the past based from data in the present ?
    i have a formula self-organizing maps
    this formula is looking for D1, D1 is neuron index that will be searched for the smallest value.and the result are D1=2 ,D2=5, D3=17 from calculating with formula  .it means the smallest value is 2, "2" from weight [2 2] in file attached.
    and then it will be in other formula
    it mean [2 2] + 0.5 ( [1 1]-[2 2] ) = [1.5 1.5]
    and the weight will be  [1.5 2 2 ] in matrix
                                              1.5 3 5
    I would appreciate any input/help on solving this
    thanks
    Attachments:
    dika.vi ‏16 KB
    weight.txt ‏1 KB
    data .txt ‏1 KB

    Hi Ronny Hanks,
    Moving your records from internal table into the database table depends upon various scenarios :-
    1. If you use INSERT statement.
    INSERT <database_table> FROM TABLE <internal_table>.
    But in this case, you need to make sure that you don't have any duplicate entries in your internal table that violates data entry into database table, else you will get a dump.
    INSERT <database_table> FROM TABLE <internal_table> ACCEPTING DUPLICATE KEYS.
    In this case, you are forcefully inserting duplicate records into your database table which may lead to data redundancy in your database table.
    2. If you use UPDATE statement.
    UPDATE <database_table> FROM TABLE <internal_table>.
    This will update the existing records in your database table from the internal table.
    3. If you use MODIFY statement.
    MODIFY <database_table> FROM TABLE <internal_table>.
    This statement works both in combination of INSERT & UPDATE statements.
    Existing records (in database table) will be eventually updated/modified and new records (not in database table currently) will be successfully inserted into the database table.
    Hope this solves your problem.
    Thanks & Regards.
    Tarun Gambhir.

  • How to show modal window without popup in a web page using javascript

    Hi,
    How to show modal window without popup in a web page using javascript, means when the modalwindow is opened it should not ask for popup blocker alert......
    pls help me.....

    Thanx for ur reply,
    Actually the senario is when i click on a button, another jsp page should be displayed in a modal window without popup, but the functions alert() and confirm() will not accept the url path of the another jsp page...

  • How to select data from a table using a date field in the where condition?

    How to select data from a table using a date field in the where condition?
    For eg:
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
                                                      and bdatu = '31129999'.
    thanks.

    Hi Ramesh,
    Specify the date format as YYYYMMDD in where condition.
    Dates are internally stored in SAP as YYYYMMDD only.
    Change your date format in WHERE condition as follows.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and bdatu = <b>'99991231'.</b>
    I doubt check your data base table EQUK on this date for the existince of data.
    Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
    data itab like equk occurs 0 with header line.
    select * from equk into table itab where werks = 'C001'
    and <b> bdatu <= '99991231'.</b>
    Thanks,
    Vinay
    Thanks,
    Vinay

  • How can I embed an DOCTYPE HTML Form from Adobe Forms central into a responsive html5 page?

    How can I embed an DOCTYPE HTML Form from Adobe Forms central into a responsive html5 page?
    -Luis

    Hi,
    You can embed the form on your website, but you need to make sure that javascript has been enabled in the browser. You need to copy the embed code and add it into your HTML code. If you would like FormsCentral to generate embeded HTML form without using javascript, you may post a feature request and vote it. Hope it helps! Thanks!
    Kind regards,
    Shiyao Bao

  • How to get  data with the raw pattern from resultset ?

    would you tell me how to get data with the raw pattern from resultset ?
    thank you in advance!
    longgger2000

    I tried getBytes() and getObject()
    , but I can not get the right result , for example the
    data in oracle database is 01000000DFFF, when In used
    the method of getBytes() and getObject(), I get the
    result of [B@1c2e8a4, very different , please tell me
    why !
    thank you
    longgger2000
    [B is byte arrayseem that it return an bytes array for you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • How do i add a personal domain to my iWeb site?

    I created a website using iWeb and logged on to mobile me to activate the personal domain I bought. It's asking me to: Add Personal Domain Before your iWeb site can be viewed at your personal domain, you must complete the following steps: Go to your

  • Script to find report columns with XXS vulnerabilities

    Hi, Report columns with display as "Standard Report Column" are vulnerable to Cross Site Scripting attacks. I have written a simple script to find these report columns and described an easy way to change them all at once. Check: http://wiki.shellprom

  • Removing spaces in an URL

    Hi, I have white spaces in my URL which I want to replace with %20. How do I do that in J2ME as I do not have "replaceall" method of Strings. thanks in advance, @debug

  • HR Form do not select any data from specific Period

    Hi All I am facing issues on the HR FORMS for Brazil related to the Remunaration Statement When I try to select any employee from a specific period (before April 2012), the system does not select any data. From April 2012 until the current period and

  • IMessage stop working

    My imessage stopped working this morning and is stuck on Waiting for activation. I went through AT&T trouble shooting with online rep but nothing worked. Anyone have a solution to a similar prob?