Key value pair relational table - cross tab / pivot out?

I have a Table of KVP and the structure is ID, Key, Value and this is the sample values...

Table with values

ID, Key, Value
TABLE 1, TRUE
1, AGE GROUP, 10
1, TRAVEL, Y
2, TABLE, FALSE
2, AGE GROUP, 20
2, TRAVEL, N

I want to turn it these date like below (output)

ID, STATUS, AGE GROUP, TRAVEL
1, TRUE, 10, Y
2, FALSE, 20 N

I read on analysis crossroads/pivot - but not able to make a query that can give me the output above. The structure of the table cannot be changed...! My bad.

Is it possible in sql, to do my output to look like above?

It is possible if you know all the possible values for the KEY:

with t as (
           select 1 id,'STATUS' key,'TRUE' val from dual union all
           select 1,'AGE GROUP','10' from dual union all
           select 1,'TRAVEL','Y' from dual union all
           select 2,'STATUS','FALSE' from dual union all
           select 2,'AGE GROUP','20' from dual union all
           select 2,'TRAVEL','N' from dual
          )
select  id,
        max(case key when 'STATUS' then val end) status,
        max(case key when 'AGE' then val end) age,
        max(case key when 'AGE GROUP' then val end) "AGE GROUP",
        max(case key when 'TRAVEL' then val end) travel
  from  t
  group by id
/

        ID STATUS AGE   AGE GROUP TRAVEL
---------- ------ ----- --------- ------
         1 TRUE         10        Y
         2 FALSE        20        N

SQL> 

If you are on 11g, you can use the PIVOT, but again, he must know the columns resulting from the outset.

Another thing, you could do is to return a list CSV key of all the values in a column using STRAGG (or LISTAGG if you are on 11.2), hierarchical queries, XML or WM_CONCAT without papers.

SY.

Tags: Database

Similar Questions

  • Don't forget to call with several key-value pairs

    I'm looking to invoke the application Remember and I try to send a title and a due date. The problem is that I don't know the format for sending multiple data items. Can someone help me with the format what should I use to having an remember entry created with a title and a due date?

    function invokeRemember (someTitle, someDate) {}
    BlackBerry.Invoke.Invoke ({}
    target: "sys.pim.remember.composer."
    Action: "bb.action.ADD."
    URI: "remember://notebookentry?title=" + someTitle + '& duedate =' + someDate;
    (}, onInvokeSuccess, onInvokeError);
    }

    I think "Ivoking Basic Applications" page shows how to do this: https://developer.blackberry.com/html5/documentation/remember.html

    It looks like you can send the following in the field of the URI:

    You can also add the following key-value pairs by adding a question mark (?) after the URI:
    
    title=
    description=
    duedate=<# SECONDS SINCE EPOCH>
    status=NotActionable, Completed, NotCompleted
    notebookid=:
    tags=
    
  • How to programmatically Exchange data (key-value pairs) with operating system called?

    Hi all

    Is there a programmatic way to Exchange data (of the key-value pairs) with the guest OS?

    We have an application that runs inside comments, and we want that this application in order to use this mechanism to Exchange data. At this point, the guest have no network connectivity. One thing that might work for us is to use the registry to the guest operating system. But I'm not sure how to handle the registry of the guest operating system.

    We looked in the VirtualMachineConfigInfo.extraConfig property, but these key-value pairs are not accessible from the comments (at least this is what I know)

    any ideas?

    Thank you

    Onur

    I think that it is better to use an environment variable or file to Exchange data with the guest operating system.

    http://www.doublecloud.org/2012/03/set-environment-variables-in-guest-operating-system-on-VMware/

    http://www.doublecloud.org/2012/03/read-environment-variables-in-guest-operating-system-on-VMware/

    If you really want the registry value,

    http://www.doublecloud.org/2012/02/run-program-in-guest-operating-system-on-VMware/

    http://en.Wikipedia.org/wiki/Windows_Registry#Command_line_editing

    Good luck!

    Steve, author of the Open Source, VMware VI and vSphere SDK VI Java API

  • To access the inside loops key/value pairs

    According to the docs of Shopify, liquid allows access to key/value pairs in for loops, as follows:

    {% for item in hash %}   {{point [0]}}: {{point [1]}} {% endfor %}

    This does not work in the liquid renderer in British Colombia; the output of the key/value tags are empty. Here is an example of using the always available this.urlculture global object:

    {   ...   {"urlculture": {"ModuleName": "urlculture", "culture": "EN"},...}

    {% for obj in this.urlculture %}

    {{ obj | json }}
    Key: {{obj [0]}}
    Value: {{obj [1]}}
    {% endfor %}

    This is the result I get:

    {
      "Key": "moduleName",
      "Value": "urlculture"
    }
    
    Key:
    Value:
    
    {
      "Key": "culture",
      "Value": "EN"
    }
    
    Key:
    Value: 

    Access by name (such as {{ obj.Key }} ) also fails.

    Am I missing something, or is this all just not yet implemented?

    Also, why isn't the nice formatting illustrated in this visible post editor in the current post code?

    Thank you, Robert.

    This was a great find. And you'll be happy to learn that we have set and it will work in the next version (unfortunately the hotfix does not update today, we have deployed on the beta version).

    You will then be able to do things like:

    {% for getParam in globals.get %}
    {{getParam[0]}} = '{{getParam[1]}}'
    {% endfor %}

    -Lucian

  • What is the best way to move with esx3.5 vmtools key/value pairs?

    Hello

    I found both candidates to store the key/value pairs for a vmware client. My ultimate goal is to run a process on the VC box that updates these data, and then read through the software tools of vm on the host (somehow) were invited.

    The first method is through 'guestinfo' settings which can be adjusted in four ways:

    Add the variable of the vmx fileprompt.
    Set the variable manually on the client (using vmwareservice.exe - cmd "infoset");
    using vmware-cmd (vmware-cmd & lt; vm-cfg-path & gt; setguestinfo & lt; variable & gt; & lt; value & gt;)
    the use of vmcom.dll COM objects (seems to be deprecated in ESX 3.5)
    These variables are easily accessible on the client by running vmwareservice.exe - cmd 'info-get guestinfo.variablename '. However, I cannot find a convenient way (better based on powershell) of their definition of a scheduled task or service to VC area.

    The second method is the customfields of guests in VItoolkit property, which can be defined as follows:

    get - vm MyVMName | Game-CustomField-nameOfValue name-value DataToBeStored
    Unfortunately, I am unable to access these data in the comments, and indeed I do not know if this is possible. If this isn't the case, I guess my only recourse would be to write a tool to connect to Web services on the VC box with a low privilege account. I prefer not to do this because it means the network infrastructure implementation to point the guest to the right VC, development of custom etc permissions...

    So, my questions are:

    • Is it possible to define variables of guestinfo through VI Toolbox, running on the virtual circuit?

    • Is it possible to read customfields on the client, through the vmtools?

    • Or is there another method to make this key/value data exchange?

    You can add/edit entries in the VMX file like this

    $vm = get-vm  | Get-View
    
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
    $vmConfigSpec.extraconfig[0].Key= "guestinfo"
    $vmConfigSpec.extraconfig[0].Value = "whatever"
    
    $vm.ReconfigVM($vmConfigSpec)
    
  • Need help to build the query/pl-sql block to get the query result and the name of column from DB table in the form of key-value pairs.

    Hi Experts,

    I have a DB table has columns of more than 50.

    I question this table, it should only return one line at any time. as sqldeveloper below image.

    here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.

    Eg:     Key                         -  Value

    TASK_EVENT_ID - 1765

    EVENT_TYPE - ASR_UPDATE

    ... etc until all of the columns in my table.

    Experts please comment on that point, appreciate your help on this.

    Thank you

    -Vincent.

    Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)

    create or replace procedure (task_expired)

    v_store_id in full,

    v_task_action_id in full,

    v_job_id in full

    )

    as

    -[SNIP code...]

    v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123';  -Your SQL here!

    v_v_val VARCHAR2 (4000);

    v_n_val NUMBER;

    v_d_val DATE;

    v_ret NUMBER;

    c NUMBER;

    d NUMBER;

    col_cnt INTEGER.

    f BOOLEAN;

    rec_tab DBMS_SQL. DESC_TAB;

    col_num NUMBER;

    vAsString VARCHAR2 (4000);

    BEGIN

    -[SNIP code...]

    Message_properties. CORRELATION: = "EDF_EVENT";

    MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();

    Msg.set_string_property ('queueName', ' shipping/csi_cth');

    Msg.set_string_property ('MODE', 'CR8');

    c: = DBMS_SQL. OPEN_CURSOR;

    DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);

    d: = DBMS_SQL. Execute (c);

    DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);

    1.col_cnt J

    LOOP

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val);      -Number

    WHEN 12 CAN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val);      -Date

    ON THE OTHER

    DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000);   -Else treat as varchar2

    END CASE;

    END LOOP;

    LOOP

    v_ret: = DBMS_SQL. FETCH_ROWS (c);

    WHEN OUTPUT v_ret = 0;

    1.col_cnt J

    LOOP

    -Fetch each column to the correct data type based on coltype

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);

    vAsString: = to_char (v_n_val);

    WHEN 12 CAN

    DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);

    vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');

    ON THE OTHER

    DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);

    vAsString: = v_v_val;

    END CASE;

    Msg.set_string_property (rec_tab (j) .col_name, vAsString);

    END LOOP;

    END LOOP;

    DBMS_SQL. CLOSE_CURSOR (c);

    DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',

    Enqueue_options => Enqueue_options,

    Message_properties => Message_properties,

    Payload-online msg,

    Msgid => Message_handle);

    dbms_output.put_line ('00 Msgid =' |) Message_handle);

    dbms_output.put_line('===Done=');

    -[SNIP code...]

    END;

    /

  • Add key/value pairs to an ArrayList from a HashMap in

    I'm trying to create a HashMap, loop through this hash table, and finally, I try to create an ArrayList of key/value - of the HashMap pairs - containing, in its set of value, a parameter value. I know that maybe it's a little difficult to understand, so I provided my code to make sense what I'm trying to accomplish.
    package data;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    
    public class ProductInventory 
    {  
        private Map <String, ArrayList<String>> product;
        private ArrayList <String> buildProduct;
        private ArrayList <ArrayList<String>> addProduct;
    
        public ProductInventory()
        {   
            /** Set default values **/
    
            product = new <String, ArrayList<String>> HashMap();
            buildProduct = new ArrayList<String> ();
            addProduct = new ArrayList<ArrayList <String>> ();
            
            /** START - Create ArrayList for each item and add to HashMap**/
    
            ArrayList <String> c1 = new ArrayList<String>();
            ArrayList <String> c2 = new ArrayList<String>();
    
            c1.add("computer"); c1.add("Apple"); c1.add("iPad2"); c1.add("499.00");
            c2.add("computer"); c2.add("Asus"); c2.add("Zenbook"); c2.add("1449.00");
    
            ArrayList <String> tv1 = new ArrayList<String>();
            ArrayList <String> tv2 = new ArrayList<String>();
    
            tv1.add("television"); tv1.add("Panasonic"); tv1.add("Viera"); tv1.add("899.00");
            tv2.add("television"); tv2.add("Samsung"); tv2.add("Series 6"); tv2.add("1597.00");
    
            ArrayList <String> a1  = new ArrayList<String>();
            ArrayList <String> a2 = new ArrayList<String>();
    
            a1.add("audio"); a1.add("Bose"); a1.add("321 GS Series III"); a1.add("999.00");
            a2.add("audio"); a2.add("Onkyo"); a2.add("HT-S3400"); a2.add("329.00"); 
    
            /** END - Create ArrayList for each item and add to HashMap **/
    
            /** Add entrys to HashMap **/
    
            product.put("CMC769LLA",c1);
            product.put("CUX31EDH72",c2);
            product.put("TVTCL50E3",tv1);
            product.put("TVUN55D6000",tv2);
            product.put("A321GSIIIBK",a1);
            product.put("AHTS3400",a2);
    
        }
    
        /** For the sake of this example, the productAttribute parameter will be equal to "computer"  **/
        
        public void setProducts(String productAttribute)
        {
                for (Map.Entry <String, ArrayList<String>> entry : product.entrySet()) /** Loop through all entrys in the HashMap **/
                {              
                    for (String s: entry.getValue()) /** Loop through all values in HashMap**/
                    {
                        /** Add product attributes **/
                        if (s.equals(productAttribute))  /** Check to see if param exists in the value set**/
                        {
                           /** Add key to buildProduct ArrayList **/
                            buildProduct.add(entry.getKey()); 
    
                             /*Loop through values of the corresponding key and add to buildProduct*/
                            for (Iterator<String> i = entry.getValue().iterator(); i.hasNext();)
                            {    
                                    Object item = i.next(); 
                                    buildProduct.add(item.toString());
                            }
                            
                            /** Add buildProduct arrayList to product arrayList **/
                            addProduct.add(buildProduct);
                            break; /** Exit nested loop**/
                        }
                    }
                }  
        }
    }
    For the desired output, it can be assumed that the value of the productAttribute parameter is "computer."

    Output current of the ArrayList addProduct:
    Size of ArrayList: [2]
    Content of each element:
    [0] - (Size [10]
          [0] - "CMC769LLA"
          [1] - "Computer"
          [2] - "Apple"
          [3] - "iPad2"
          [4] - "499.00"
          [5] - "CUX31EDH72"
          [6] - "Computer"
          [7] - "Asus"
          [8] - "Zenbook"
          [9] - "1449.00"
    [1] - (Size [10])
         /**  It includes the exact same content as element [0] **/
    Desired output of the ArrayList addProduct:
    Size of ArrayList: [2]
    Content of each element:
    [0] - (Size [5])
          [0] - "CMC769LLA"
          [1] - "Computer"
          [2] - "Apple"
          [3] - "iPad2"
          [4] - "499.00"
    [1] - (Size [5])
          [0] - "CUX31EDH72"
          [1] - "Computer"
          [2] - "Asus"
          [3] - "Zenbook"
          [4] - "1449.00"
    I can't understand what I'm doing wrong. Any help would be greatly appreciated.

    You have defined buildProduct and then add to it.

    buildProduct = new ArrayList ();
    

    Do this assignment at the top of each loop so that a new ArrayList is allocated.

    1 buildProduct = new ArrayList () ;
    2. Add your 4 things using buildProduct.add
    3. Add buildProduct to your 'mother' object - addProduct.add (buildProduct);
    4. loop back to step 1 and create a new arraylist to the next set of elements

  • How can I navigate another feature of a local html and remote html url and transmit data or the key, value pair?

    Hello

    I'm trying to integrate a local html file and a remote url base html file MAF 2.0.1 based app. I want to access another device (based amx) on click of a button on the html pages. How can I achieve the same?

    Already tried with the below which fails with call javascript directly on the page html itself.

    -HTML-

    <! DOCTYPE html >

    < html >

    < head >

    < meta http-equiv = "Content-Type" content = text/html"; charset = windows-1252 "/ >"

    Home < title > < /title >

    < script type = "text/javascript" >

    document.addEventListener ("deviceready", callfeature, false);

    function callfeature() {}

    Alert ("callfeature called to map");

    adf.mf.api.gotoFeature ("sni.gps.demo.locationFeature", function (req, res) {})

    Alert ("full gotoFeature");

    },

    function (req, res) {}

    Alert ("gotoFeature failed with" + adf.mf.util.stringify (res));

    });

    Alert ("callfeature called to map closed");

    }

    < /script >

    < / head >

    < body >

    Simple mobile Web Page < h1 > < / h1 > < form method = "get" >

    < input id = "ip1" name = "name" / >

    <!-a href = "mycustomurlscheme://somedata" id = "myurl" > map < / a->

    < button type = "button" id = 'mybtn' name = "gpsbtn" onclick = "callfeature ()" >

    go to the feature

    < / button >

    < / make >

    < / body >

    < / html >

    Hello

    update to 2.1 MAF gives you , that can be added to HTML files the and remote access to the MAF since JavaScript API. Deepak mentioned "adf.mf.api.gotoFeature" and I can confirm it works HTML distance (and so it should be using local HTML). For the transmission of data, not sure whether the request URL object it. I would try here EL referencing a managed bean of application-scope defined in the scope of application (?). I tried beans controlled but so far has not tried to access the managed beans to a feature local or remote HTML using EL (although the EL is here)

    Frank

  • How to read file(key-value) in OSB properties?

    Hello

    I have a scenario in which I have to read a few properties(key-value) in a file. Former entire code was developed in java and it is easy to read the java properties file.
    But now I need to implement this in OSB and performance is a crucial element in this project.

    I followed DVM approached defined in

    http://blogs.Oracle.com/christomkins/2010/02/domain_value_maps_in_oracle_se.html and http://blogs.oracle.com/christomkins/2010/02/domain_value_maps_in_oracle_se.html

    But it did not work. I have hundreds of properties (key-value pairs) to read and must transmit it to the service of the company and with the intervention of the proxy service.

    What is the best approach for this (can't go to db call performance being very critical)?

    Thank you
    Maryse

    Hello Francois,.

    XPath in the action assign OSB should be like -

    $DVMVar / ns1:rows[1]/ns1:row[1]/ns1:cell[1]/text()

    where DVMVar is the content below -








    Dealer.Locate.default.buypower.Link
    http://www.xyz.com


    dealer.locate.default.unitOfMeasure
    MILES


    Dealer.Locate.Brand.identifier.nu
    Nurun


    Dealer.Locate.Brand.identifier.bu
    Buick


    Dealer.Locate.Brand.identifier.ca
    Cadillac


    Kind regards
    Anuj

  • How to combine the large number of tables of pair key / value in a single table?

    I have a pair key / value tables of 250 + with the following features

    (1) keys are unique within a table but may or may not be unique in the set of tables
    (2) each table has about 2 million lines

    What is the best way to create a single table with all unique key-values of all these paintings? The following two queries work up to about 150 + tables
    with
      t1 as ( select 1 as key, 'a1' as val from dual union all
              select 2 as key, 'a1' as val from dual union all
              select 3 as key, 'a2' as val from dual )
    , t2 as ( select 2 as key, 'b1' as val from dual union all
              select 3 as key, 'b2' as val from dual union all
              select 4 as key, 'b3' as val from dual )
    , t3 as ( select 1 as key, 'c1' as val from dual union all
              select 3 as key, 'c1' as val from dual union all
              select 5 as key, 'c2' as val from dual )
    select coalesce(t1.key, t2.key, t3.key) as key
    ,      max(t1.val) as val1
    ,      max(t2.val) as val2
    ,      max(t3.val) as val3
    from t1
    full join t2 on ( t1.key = t2.key )
    full join t3 on ( t2.key = t3.key )
    group by coalesce(t1.key, t2.key, t3.key)
    /
    
    with
      master as ( select rownum as key from dual connect by level <= 5 )
    , t1 as ( select 1 as key, 'a1' as val from dual union all
              select 2 as key, 'a1' as val from dual union all
              select 3 as key, 'a2' as val from dual )
    , t2 as ( select 2 as key, 'b1' as val from dual union all
              select 3 as key, 'b2' as val from dual union all
              select 4 as key, 'b3' as val from dual )
    , t3 as ( select 1 as key, 'c1' as val from dual union all
              select 3 as key, 'c1' as val from dual union all
              select 5 as key, 'c2' as val from dual )
    select m.key as key
    ,      t1.val as val1
    ,      t2.val as val2
    ,      t3.val as val3
    from master m
    left join t1 on ( t1.key = m.key )
    left join t2 on ( t2.key = m.key )
    left join t3 on ( t3.key = m.key )
    /

    A couple of questions, then a possible solution.

    Why the hell you have 250 + tables pair key / value?

    Why the hell you want to group them in a table containing one row per key?

    You could do a pivot of all the tables, not part. something like:

    with
      t1 as ( select 1 as key, 'a1' as val from dual union all
              select 2 as key, 'a1' as val from dual union all
              select 3 as key, 'a2' as val from dual )
    , t2 as ( select 2 as key, 'b1' as val from dual union all
              select 3 as key, 'b2' as val from dual union all
              select 4 as key, 'b3' as val from dual )
    , t3 as ( select 1 as key, 'c1' as val from dual union all
              select 3 as key, 'c1' as val from dual union all
              select 5 as key, 'c2' as val from dual )
    select key, max(t1val), max(t2val), max(t3val)
    FROM (select key, val t1val, null t2val, null t3val
          from t1
          union all
          select key, null, val, null
          from t2
          union all
          select key, null, null, val
          from t3)
    group by key
    

    If you can do it in a single query, Union all 250 + tables, you don't need to worry about chaining or migration. It may be necessary to do this in a few passes, depending on the resources available on your server. If so, I would be inclined to first create the table, with a larger than normal free percent, making the first game as a right inset and other pass or past as a merger.

    Another solution might be to use the approach above, but limit the range of keys with each pass. So pass we would have a like predicate when the key between 1 and 10 in every branch of the union, pass 2 would have key between 11 and 20, etc. In this way, everything would be straight inserts.

    That said, I'm going back to my second question above, why the hell you want or need to do that? What is the company you want to solve. There could be a much better way to meet the requirement.

    John

  • Using XML as a pair key / value in OSB 11 g

    Hi all

    I made a new Test project. There are only 2 files:
    1 proxies - that contain proxy services
    2 xml - containing XMLs

    An example of XML (XML name - TestXML) present in the xml file:

    < valueDetails >
    ABC < key1 > < / key1 >
    < > 123 key2 < / key2 >
    a12s < key3 > < / key3 >
    < / valueDetails >

    I want to use in the pipeline of proxy as key-value property services. How do I get there?

    I use OSB 11 GR 1 material.

    Thanks in advance!

    Kind regards
    Karthik.

    Save the XML as a resource of xquery to the osb. Then, use an entitled action for load in the pipeline. For example affect XQuery resources KeyPairsXML to $keypairs. After this $keypairs will be your xml and appropriate xpath allows to recover the key you want,

  • Cannot get the value of the column amount in Pivot Table Preview

    Hi all
    I have the XML data and creating PivotTable to cross tab report RTF.
    I have the coulumn of the year which is dynamic. Under the present the amount displayed as zero 0 in preview. But the data are available in the XML file.

    Please let me know if something is missing.

    Thank you.

    Hi Adam,.

    The latter, a lot of scenario here, see
    http://winrichman.blogspot.com/search/label/cross%20tab

  • Cross Tab with group by period

    Good afternoon

    I wonder if some can help me with this query, I am writing?

    The cross-tab is for columns 1 to 31, representing the days of the month, sum of the quantity of an article sold.

    In addition the company description.

    I would then finish with 3 entrances in the results for each company, but these are for the sum of the quantity of items in the following periods: -.

    Breakfast: 01:00 - 10:00
    Lunch: 11:00 - 14:00
    Dinner: 17:00 - 22:30

    Yes, the company is closed for the missing periods, for example 10:00-11:00 & 14:00 to 17:00.

    Test case:
    CREATE TABLE COMPANIES
      (
        "ID"            NUMBER(9,0),
        "CODE"          NUMBER(8,0),
        "DESCRIPTION"   VARCHAR2(40 CHAR),
        CONSTRAINT "PK_COMPANIES" PRIMARY KEY ("ID")
      );
    
    INSERT INTO COMPANIES VALUES (1,1,'COMPANY A');
    INSERT INTO COMPANIES VALUES (2,2,'COMPANY B');
    INSERT INTO COMPANIES VALUES (3,3,'COMPANY C');
    
    
    CREATE TABLE CUSTOMERS
      (
        "ID"                     NUMBER(9,0),
        "CODE"                   VARCHAR2(30 CHAR),
        "CARD_NUM"               VARCHAR2(30 CHAR),
        "DESCRIPTION"            VARCHAR2(40 CHAR),
        "COMPANY_ID"                   NUMBER(9,0),
        CONSTRAINT "PK_CUSTOMERS" PRIMARY KEY ("ID")
      );
    
    INSERT INTO CUSTOMERS VALUES (1,'001','001','A CUSTOMER', 1);
    INSERT INTO CUSTOMERS VALUES (2,'002','002','A CUSTOMER', 2);
    INSERT INTO CUSTOMERS VALUES (3,'003','003','A CUSTOMER', 3);
    INSERT INTO CUSTOMERS VALUES (4,'004','004','A CUSTOMER', 1);
    INSERT INTO CUSTOMERS VALUES (5,'005','005','A CUSTOMER', 2);
    INSERT INTO CUSTOMERS VALUES (6,'006','006','A CUSTOMER', 1);
    
    
    CREATE TABLE ARTICLES
      (
        "ID"                     NUMBER(9,0),
        "CODE"                   VARCHAR2(20 CHAR),
        "DESCRIPTION"            VARCHAR2(40 CHAR),
        CONSTRAINT "PK_ARTICLES" PRIMARY KEY ("ID")
      );
    
    INSERT INTO ARTICLES
      VALUES (1,'001', 'A Meal');
    
    
    
    CREATE TABLE TRANSACTIONS
      (
        "ID"          NUMBER(9,0),
        "TILL_ID"     NUMBER(9,0) NOT NULL ENABLE,
        "SHOP_ID"     NUMBER(9,0) NOT NULL ENABLE,
        "OPERATOR_ID" NUMBER(9,0),
        "TRANS_NUM"   NUMBER(5,0) NOT NULL ENABLE,
        "SPLIT_NUM"   NUMBER(5,0),
        "TRANS_DATE" DATE NOT NULL ENABLE,
        "TOTAL_AMOUNT"      NUMBER(12,2) NOT NULL ENABLE,
        "BOOKKEEPING_DATE" DATE NOT NULL ENABLE,
        "CARD_NUM"           VARCHAR2(30 CHAR),
        CONSTRAINT "PK_TRANSACTIONS" PRIMARY KEY ("ID")
      );
    
    INSERT INTO TRANSACTIONS VALUES (1,1,1,1,1,NULL,to_date('27.04.2011 10:30:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'001');
    INSERT INTO TRANSACTIONS VALUES (2,1,1,1,1,NULL,to_date('27.04.2011 10:31:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'002');
    INSERT INTO TRANSACTIONS VALUES (3,1,1,1,1,NULL,to_date('27.04.2011 10:32:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'003');
    INSERT INTO TRANSACTIONS VALUES (4,1,1,1,1,NULL,to_date('27.04.2011 10:33:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'004');
    INSERT INTO TRANSACTIONS VALUES (5,1,1,1,1,NULL,to_date('27.04.2011 10:34:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'005');
    INSERT INTO TRANSACTIONS VALUES (6,1,1,1,1,NULL,to_date('27.04.2011 10:35:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'006');
    INSERT INTO TRANSACTIONS VALUES (7,1,1,1,1,NULL,to_date('27.04.2011 14:30:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'001');
    INSERT INTO TRANSACTIONS VALUES (8,1,1,1,1,NULL,to_date('27.04.2011 14:31:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'002');
    INSERT INTO TRANSACTIONS VALUES (9,1,1,1,1,NULL,to_date('27.04.2011 14:32:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'003');
    INSERT INTO TRANSACTIONS VALUES (10,1,1,1,1,NULL,to_date('27.04.2011 14:33:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'004');
    INSERT INTO TRANSACTIONS VALUES (11,1,1,1,1,NULL,to_date('27.04.2011 14:34:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'005');
    INSERT INTO TRANSACTIONS VALUES (12,1,1,1,1,NULL,to_date('27.04.2011 14:35:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'006');
    INSERT INTO TRANSACTIONS VALUES (13,1,1,1,1,NULL,to_date('27.04.2011 22:00:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'001');
    INSERT INTO TRANSACTIONS VALUES (14,1,1,1,1,NULL,to_date('27.04.2011 22:01:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'002');
    INSERT INTO TRANSACTIONS VALUES (15,1,1,1,1,NULL,to_date('27.04.2011 22:02:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'003');
    INSERT INTO TRANSACTIONS VALUES (16,1,1,1,1,NULL,to_date('27.04.2011 22:03:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'004');
    INSERT INTO TRANSACTIONS VALUES (17,1,1,1,1,NULL,to_date('27.04.2011 22:04:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'005');
    INSERT INTO TRANSACTIONS VALUES (18,1,1,1,1,NULL,to_date('27.04.2011 22:05:05', 'DD.MM.YYYY HH24:MI:SS'),0.01,to_date('27.04.2011', 'DD.MM.YYYY'),'006');
    
    CREATE TABLE TRANS_ARTICLES
      (
        "TRANSACTION_ID"        NUMBER(9,0) NOT NULL ENABLE,
        "ARTICLE_ID"            NUMBER(9,0) NOT NULL ENABLE,
        "QTY_WEIGHT"            NUMBER(10,3) NOT NULL ENABLE,
        "PRICE"                 NUMBER(10,2) NOT NULL ENABLE,
        CONSTRAINT "PK_TRANS_ARTICLES" PRIMARY KEY ("TRANSACTION_ID")
      )
    
    INSERT INTO TRANS_ARTICLES VALUES (1,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (2,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (3,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (4,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (5,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (6,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (7,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (8,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (9,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (10,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (11,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (12,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (13,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (14,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (15,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (16,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (17,1,1,0.01);
    INSERT INTO TRANS_ARTICLES VALUES (18,1,1,0.01);
    With similar results to: -.
    1     Company A - 01:00 10:00     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0
    1     Company A - 11:00 14:00     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0
    1     Company A - 17:00 22:30     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     3     0     0     0     0
    2     Company B - 01:00 10:00     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     1     0     0     0     0
    2     Company B - 11:00 14:00     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     0     0     0     0
    2     Company B - 17:00 22:30     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     2     0     0     0     0
    This is the Group of periods which is I don't know how to do.

    Thank you & best regards,

    Andrew

    Hello

    Here's a way to do it:

    WITH     all_time_slots     AS
    (
         SELECT  '01:00 - 11:00' AS label,  1 / 24 AS start_time, 11 / 24 AS end_time     FROM dual
         UNION ALL
         SELECT  '12:00 - 15:00',       12 / 24,               15 / 24          FROM dual
         UNION ALL
         SELECT  '17:00 - 23:30',          17 / 24,               23.5 / 24          FROM dual
    )
    ,     all_days     AS
    (
         SELECT     LEVEL     AS day_of_month
         FROM     dual
         WHERE     LEVEL     IN (1, 27, 31)          --     *****  FOR TESTING ONLY  *****
         CONNECT BY     LEVEL     <= 31
    )
    ,     inner_joins     AS
    (
         SELECT       EXTRACT  (DAY  FROM  tr.bookkeeping_date)     AS day_of_month
         ,       tr.trans_date
         ,       ta.qty_weight
         ,       cu.company_id
         FROM       articles            ar
         JOIN       trans_articles       ta  ON   ta.article_id     = ar.id
         JOIN       transactions              tr  ON   tr.id          = ta.transaction_id
         JOIN       customers            cu  ON   cu.card_num          = tr.card_num
               WHERE       ar.description       = 'A Meal'
               AND       tr.bookkeeping_date  >= DATE '2011-04-01'
         AND       tr.bookkeeping_date  <  DATE '2011-05-01'
    )
    ,     unpivoted_data     AS
    (
         SELECT       co.description
         ,       ad.day_of_month
         ,       NVL (ij.qty_weight, 0)     AS weight_0
         ,       ts.label
         FROM            companies       co
         CROSS JOIN        all_time_slots  ts
         CROSS JOIN       all_days       ad
         LEFT OUTER JOIN       inner_joins       ij   ON   ij.company_id     = co.id
                                              AND  ij.day_of_month     = ad.day_of_month
                                              AND  ij.trans_date - TRUNC (ij.trans_date)
                                                                 BETWEEN  ts.start_time
                                                        AND          ts.end_time
    )
    SELECT       *
    FROM       unpivoted_data
    PIVOT       (     SUM (weight_0)
           FOR     day_of_month     IN
                (      1     AS day_1
              ,     27     AS day_27
              ,     31     AS day_31
              )
           )
    ORDER BY  description
    ,            label
    ;
    

    Ouput, given the example of data that you changed it about an hour ago:

    DESCRIPTION LABEL              DAY_1     DAY_27     DAY_31
    ----------- ------------- ---------- ---------- ----------
    COMPANY A   01:00 - 11:00          0          3          0
    COMPANY A   12:00 - 15:00          0          3          0
    COMPANY A   17:00 - 23:30          0          3          0
    
    COMPANY B   01:00 - 11:00          0          2          0
    COMPANY B   12:00 - 15:00          0          2          0
    COMPANY B   17:00 - 23:30          0          2          0
    
    COMPANY C   01:00 - 11:00          0          1          0
    COMPANY C   12:00 - 15:00          0          1          0
    COMPANY C   17:00 - 23:30          0          1          0
    

    Sorry, I'm short on time right now.  I'll try to post an explanation in 4 hours approximately.
    See my next post for an explanation.

    Published by: Frank Kulash, 28 April 2011 21:29

  • cross tab using sql

    Hello

    I'm using the version of oracle 11g.

    I have a requirement where I have to produce a cross-tab as explained below. Please help me write a SQL query to do this. Thank you very much.


    Sample data:
    ------------------
    Customer             product type
    --------------------------------------------
    AAA                           DVD
    AAA                           Tape
    BBB                           Tape
    CCC                                 DVD
    CCC                           Bluray
    DDD                           DVD
    DDD                           Tape
    DDD                           Bluray
    Logic
                                                                                    
         AAA                                              BBB                         CCC                         DDD          
         DVD     Tape     Bluray                    DVD     Tape     Bluray               DVD     Tape     Bluray               DVD     Tape     Bluray
    DVD          1                    DVD                         DVD               1          DVD          1     
    Tape     1                         Tape          1               Tape                         Tape     1          1
    Bluray                              Bluray                         Bluray     1                    Bluray          1     
    Final Output
    No. of customers who purchased the products across all product types
                        
         DVD     Tape     Bluray               
    DVD          2     1               
    Tape     2     1     1               
    Bluray     1     1                    
    Scripts:
    -------------------------
    create table cust_product(customer varchar2(5), product_type varchar2(10));
    
    insert into cust_product values('AAA','DVD');
    insert into cust_product values('AAA','Tape');
    insert into cust_product values('BBB','Tape');
    insert into cust_product values('CCC','DVD');
    insert into cust_product values('CCC','Bluray');
    insert into cust_product values('DDD','DVD');
    insert into cust_product values('DDD','Tape');
    insert into cust_product values('DDD','Bluray');

    Hello

    858747 wrote:
    ... Sample data:
    ------------------

    Customer             product type
    --------------------------------------------
    AAA                           DVD
    AAA                           Tape
    BBB                           Tape
    CCC                                 DVD
    CCC                           Bluray
    DDD                           DVD
    DDD                           Tape
    DDD                           Bluray
    

    ...
    Final output
    N ° of guests who have purchased products for all types of product

    `     DVD     Tape     Bluray
    DVD          2     1
    Tape     2     1     1
    Bluray     1     1                    
    

    Sorry, I don't follow the logic. Try to explain in words, with specific examples.
    Doesn't have 2 separate clients, 'CCC' and 'DDD', buy 'DVD' and 'Bluray '? Why aren't the results

    `     DVD     Tape     Bluray
    DVD          2     2
    Tape     2     1     1
    Bluray     2     1                    
    

    with 2 in the corners?

    Assuming it was just error, you can do something like this:

    WITH     got_pairs     AS
    (
         SELECT       a.product_type               AS product_a
         ,       NVL (b.product_type, a.product_type)     AS product_b
         FROM            cust_product     a
         LEFT OUTER JOIN     cust_product     b  ON  a.customer     = b.customer
                                AND     a.product_type != b.product_type
    )
    SELECT       *
    FROM       got_pairs
    PIVOT       (     COUNT (*)
           FOR     product_b
           IN     ( 'DVD'
              , 'Tape'
              , 'Blueray'
              )
           )
    ORDER BY  CASE  product_a
              WHEN  'DVD'     THEN  1
              WHEN  'Tape'     THEN  2
              WHEN  'Bluray'     THEN  3
           END
    ;
    

    This assumes that the combination (customer, product_type) is unique, as in your example of data., and that only product_types is 3 in your sample data.
    If these assumptions are not true, then after a few revised sample data and results, which show what you want in these cases.

    Sorry, I don't have an Oracle 11 database now to test this.
    I can (and has) test the outer join, which combines a product_type with him that if he can not be combined with any other thing.

    Using a technique of 11 pivot before Oracle, the following works:

    WITH     got_pairs     AS
    (
         SELECT       a.product_type               AS product_a
         ,       NVL (b.product_type, a.product_type)     AS product_b
         FROM            cust_product     a
         LEFT OUTER JOIN     cust_product     b  ON  a.customer     = b.customer
                                AND     a.product_type != b.product_type
    )
    SELECT       product_a     AS product_type
    ,       COUNT (CASE WHEN product_b = 'DVD'    THEN 1 END)     AS dvd
    ,       COUNT (CASE WHEN product_b = 'Tape'   THEN 1 END)     AS dvd
    ,       COUNT (CASE WHEN product_b = 'Bluray' THEN 1 END)     AS dvd
    FROM       got_pairs
    GROUP BY  product_a
    ORDER BY  CASE  product_a
              WHEN  'DVD'     THEN  1
              WHEN  'Tape'     THEN  2
              WHEN  'Bluray'     THEN  3
           END
    ;
    

    Note that the got_pairs of the subquery is identical in the two motions.

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

    Published by: Frank Kulash, may 29, 2011 16:05
    Oracle 9 append query.

  • With the help of several key values to find the data

    Hello, it's me again.

    I had a question out about data from database and display them on a page of the ADF on Jdev 11.1.1.3.

    And Mr. Daniel Atwood answered my question with this blog to follow, that wrote.
    http://www.avioconsulting.com/blog/datwood/2012/06/19/using-BPM-process-variable-ADF-form-retrieve-database-information-0.

    But I have another question on top that.

    The Mr.Atwood example is when using a value of key 'one', what happens if I have two key values, how to set?

    Here are some details:

    I have a table like this

    ID Type_code name
    0001 05 a-blabla
    0002 b 25-blabla
    0002 26 b-blabla
    0003-08 c-blabla
    0003 25 c-blabla
    0003 c 79-blabla

    What I want to do is after the entry of the ID (0003) and type_code (25), he will show me the result on three components of text entry in the ADF with the value 0003, 25 page and c-blabla.

    Currently, I use only ID to query the data, but I would use two key values to find specific data.

    Thank you very much for taking the time to think about it,

    Sincerely,

    Alto

    If you had multiple values to use for the request, one approach would be to create a display object. Whether you are creating the view object, in step 6, you will add two bind variables. Call a "pTypeCode" and call the other "pId". Click on the back button so that you're still in step 5, and modify the WHERE clause as follows:

    (ID = :pId) and (Type_code = :pTypeCode)
    

    After you have done this, double-click the Module of the Application and add your new view object. In the tab control of data, click the Refresh button. Expand your new view object tab of data control-> expand "French"-> note that you now have a new method called "ExecuteWithParams".

    Open your workflow diagram-> delete your existing "SetCurrentRowKeyValues" method-> made slide on your new "ExecuteWithParams" operation on the diagram. When you do so, you should see two settings you need to complete the dialog box. Just as you did before with the SetCurrentRowKeyValue method, set the values for the pTypeCode and the nest.

    Add the case of control flow of the new method to your existing view-> make the new method, the default value.

    On your form, remove the fields that have been placed here who uses the old object from view. On the tab of data control, drag the fields you want to be placed on the inside of your new view object form.

    Dan

Maybe you are looking for

  • HP compact microtour dx7300: update firmware hp dx7300 format microtour

    Hello everyone here please help me. I have hade pc hp dx7300 1.8 ghz dual core running. I want to spend to 2.7 ghz dual core E5700.  After you change the processor and spend it on the pc when you start code 1801 appear and my colling fan runs full sp

  • Pavilion dv7-4138eo: dv7-4138eo

    What is the number of the motherboard with amd prosessor model dv7-4138eo? 603939 001 is suitable?

  • NT AUTHORITY\ANONYMOUS LOGON what does this mean?

    Event type: Success AuditEvent source: securityEvent category: opening/closing sessionEvent ID: 540Date: 31/05/2012Time: 09:22:52User: NT AUTHORITY\ANONYMOUS LOGONComputer: The-F20B3C162B1Description:Network logon successful:User name:Domain:Logon ID

  • Learn sharepoint

    I'm willing to learn sharepoint myself. I don't know anything about sharepoint. You can recommend books that are good for me as a beginner?

  • Connected my laptop to the TV. now, the computer screen is magnified

    Hello I connected my HP Pavilion g7 on my big screen tv Vizio. When I disconnected the laptop to the TV, the computer screen is enlarged, as he thinks he has the same size screen as television. I tried several things to fix.  I did a restore of the s