Help returns the array of query results

Hi all... Pretty new to this so please forgive my ignorance. Running Oracle 11 g, trying to return results as in the example I give below. I don't know how the Sport field will have unique values, and I don't know how many unique values the year field is seen in the data. Does anyone have recommendations/suggestions?

The structure of the table is:
Year of sport
Baseball 10-11
Football 10-11
Football 11-12
Football 11-12
Football 11-12
Baseball 11-12

The result should be sports in each year and should be grouped by year but shown as columns so:
(GROUP OF the year)
1, baseball 1, Football
2, 1, Football Soccer 1, Baseball


I hope that makes sense. Thanks for any help!
... Kaelon

Does anyone have recommendations/suggestions?

Maybe something like:

SQL> with t as (
 select 'Baseball' sport, '10-11' year from dual union all
 select 'Football', '10-11' from dual union all
 select 'Football', '11-12' from dual union all
 select 'Football', '11-12' from dual union all
 select 'Soccer',   '11-12' from dual union all
 select 'Baseball', '11-12' from dual
)
--
--
select year, listagg(cnt || ', ' || sport, ' ') within group (order by cnt desc) sports from (
select count(*) cnt, sport, year from t
group by sport, year)
group by year
/
YEAR    SPORTS
------- ----------------------------------------
10-11   1, Baseball 1, Football
11-12   2, Football 1, Baseball 1, Soccer       

2 rows selected.

?

Tags: Database

Similar Questions

  • Help on the game of query results

    Hi gurus,

    Have this survey for my requirement of dataset sql.

    Sample, it's that I have to pick up the nonfunctional currency transactions.

    Lets say for a given month, data that are present are for CurrencyA and CurrencyB for a particular account.

    Account1 has a transaction does not work CurrencyA and CurrenyB then Account2 has only transaction to CurrencyB.

    My current query result is that the 3 first lines, what I need is the 4th should also appear and be included.

    CurrencyA - amount - account1

    CurrencyB - amount - account1

    CurrencyB - amount - Account2

    CurrencyA - < '0' / or null >-Account2

    I think that my request is based on the currency < x > I have, so it should be for each account, he has all the lines for each currency.

    If please notify and let me know your thoughts.

    Kind regards

    Hello

    It looks like you want an outer join partitioned.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

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

  • Input processor may not return the array

    Hi all

    I've set up an EntryProcessor to return the results of the calculated amounts, however, under the exception is thrown when retrieving the result. Any idea? I tried to change to return BigDecimal instead of BigDecimal [], it works. Why?

    Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; incompatible with [Ljava.math.BigDecimal;


    BigDecimal results = (BigDecimal []) CacheHelper.getCounterPartyCache () .invoke (new FttCntptId("052753"), new CreateOrderProcessor());

    Henry

    922963 wrote:
    Hi all

    I've set up an EntryProcessor to return the results of the calculated amounts, however, under the exception is thrown when retrieving the result. Any idea? I tried to change to return BigDecimal instead of BigDecimal [], it works. Why?

    Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; incompatible with [Ljava.math.BigDecimal;

    BigDecimal results = (BigDecimal []) CacheHelper.getCounterPartyCache () .invoke (new FttCntptId("052753"), new CreateOrderProcessor());

    Henry

    Hi Henry,.

    It can return the paintings, but he cannot return correctly typed arrays.

    On the client side, this table has been deserialized as an Object [] and not as a BigDecimal [] and, therefore, it cannot be cast to BigDecimal [].

    So just change the declaration of the Object [] results variable and do the distribution on the elements instead.

    Best regards

    Robert

  • VcHostVirtualSwitch 'portgroup' object property returns the array of channels, no objects

    Something seems a little wrong here; on a vSphere 5.5 installation, you ask a traditional vSwitch (IE not dvSwitch) for exchanges that I do not receive the table of object of type [VcHostPortGroup], but rather an array of flat strings that cannot be extended.

    This seems to break the shares provided for registration of trade as well as my own code, so I suspect that some changes in the API 5.5 can have passed unnoticed since so few people more uses vSwitches.

    Could someone check the following code and see what happens:

    var hosts=Server.findAllForType("VC:HostSystem");
    
    
    var host=hosts[0];
    var switches=host.configManager.networkSystem.networkInfo.vswitch;
    
    for (var i=0; i<switches.length; i++) {
      vswitch=switches[i];
      System.log(vswitch);
      var pglist=vswitch.portgroup;
      for (var n=0;n<pglist.length;n++) {
      var pg=pglist[n];
      System.log (pg);
    System.log("Found portgroup "+ pg.spec.name +" with vlan ID "+pg.spec.vlanId); // This breaks
      }
    }
    
    

    Okay, so I figured this out on my own.

    There is a bug in the documentation in the API of vCO HostVirtualSwitch object does not point to a group of ports, but rather returns an array of strings "flattened" with the keys (not unique, useless) to the port associated with the vSwitch groups. It is correctly stated in the vSphere API reference but incorrect in the version of vCO, which may indicate that the code real vCO is incompatible as well.

    To recover a real populated HostPortGroup object you must descend through the successful HostNetworkInfo object; the portgroup here property is an array of the appropriate type.

  • Calling a database procedure which returns the array as output parameters

    Hello


    I wanted to call a procedure that returns "T_Disponibilidad_Diaria".

    Type T_Disponibilidad_Diaria is Table of the R_Disponibilidad_Diaria
    INDEX OF DIRECTORY;


    Type R_Disponibilidad_Diaria is {Record

    }

    Please suggest me the best way to convert this type of array complex java object
    Thanks in advance


    Concerning
    Vidya

    But what you can do...

    Try to create a new stored procedure, which returns the type of the database object.
    In this procedure, you can call the original procedure.
    Take what it returns and make the type object. That's what you need to retrieve your procedure ;-) (.. .huh?)

  • limit the number of query results for content Presenter CMIS

    Hi dear,

    I have a problem. I added content present on my page in Jdev ide, not at run time. And I need a query including the limitation of the number of results.

    My query is: ${' SELECT * from ora: t:IDC:GlobalProfile WHERE the ora: p:xRegionDefinition =-"CSGMNEWS_REGDEF\" ORDER BY ora: p:dInDate DESC'}


    I just want to add a number parameter.

    Can you help me please? How can I limit the number of results?

    Kind regards

    Yacouba

    Published by: erdo on 21.Mar.2013 18:37

    Hello.

    Content Presenter has a setting (maxResults) to set the maximum returned results:

    Sample:

    xmlns = "http://xmlns.oracle.com/adf/controller/binding" Refresh 'ifNeeded' = >







    When you add your CP to a page at design time, you can access the pageDefinition and provide more values for attributes of CP.

    I hope this help you.

    Kind regards.

  • the case-insensitive query results

    I got a help from 11g with the suite of version information

    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE Production 11.1.0.7.0
    AMT for 32-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production

    The result of the query are case-sensitive

    Ex: Select * from Table_1 where column like '% new % ';

    result: News

    But do not go back NEWS News or news

    The result of the query are case-sensitive

    But you want the results to be case-insensitive?
    Well, then you can use:

    Select * from Table_1 where lower(column) like '%news%';
    

    And use a function based index.

  • How to speed up the time to query result

    When executing the following query, the result comes after 22 seconds.

    How I minimize this time? Please suggest.
    SELECT DISTINCT
           PERIOD_NO,
           ITEM_CODE,
           ITEM_NAME,
           SUM(CASE WHEN LEVEL_TYPE IN 'SUB ZONE' THEN WD_FORECAST_QTY_BU / CNV / ML ELSE 0 END)TOT_FRCST
    FROM   SHEET_HEAD, SHEET_DETAIL, ITEM_DETAIL
    WHERE  WH_SYS_ID = WD_WH_SYS_ID 
    AND    ITEM_CODE = WD_ITEM_CODE(+)
    AND    PERIOD_NO BETWEEN :PERIOD1 AND :PERIOD2
    AND    WH_REVISION_NO = 0 
    AND    WH_LEVEL_CODE NOT IN (SELECT WH_LEVEL_CODE FROM SHEET_HEAD WHERE WH_REVISION_NO = 1)
    GROUP BY   ITEM_CODE, ITEM_NAME, WH_PERIOD_NO
    Sanjay

    Hello

    with speed suggest it would be always be expirement with indexing on parameters, after that first scans all what is currently happening in what concerns analyses of full table etc. which are "more expensive."

    Level of the specific actions on your code, that what follows comes out too expensive; -

    AND    WH_LEVEL_CODE NOT IN (SELECT WH_LEVEL_CODE FROM SHEET_HEAD WHERE WH_REVISION_NO = 1)
    

    Here, I would see if you can rewrite, perhaps with a left join / auto join to achieve the same ends, compare the timings, you might be surprised.

    Kind regards

    Robert.

  • Help of the complex select query (Group by)

    Hello
    I am in need of your help to create a unique select query for the data in the table below and whose output requies. I use oracle 10g on RHEL 5 version.

    create table bustour (number of bussno (4), start_date date, number (2)) passenger;
    ALTER session set nls_date_format = "dd-mm-yyyy";
    insert into bustour values (4123, April 10, 2009 ", 20);
    insert into bustour values (4123, may 10, 2009 ", 25);
    insert into bustour values (4123, may 10, 2009 ', 18);
    insert into bustour values (4123, June 10, 2009 ', 15);

    insert into bustour values (6138, March 10, 2009 ', 16);
    insert into bustour values (' 6138, March 10, 2009 ", 19);
    insert into bustour values (6138, April 10, 2009 ', 22);
    insert into bustour values (' 6138, April 10, 2009 ", 13);

    insert into bustour values ("4123, July 10, 2009 ', 23);
    insert into bustour values (4123, August 10, 2009 ", 27);
    insert into bustour values (4123, November 10, 2009 ', 15);

    insert into bustour values (6138, may 10, 2009 ', 16);
    insert into bustour values (6138, may 10, 2009 ', 13);
    insert into bustour values (6138, may 10, 2009 ', 18);
    insert into bustour values (' 6138, may 10, 2009 ", 24);
    insert into bustour values (6138, July 10, 2009 ", 20);
    insert into bustour values (6138, August 10, 2009 ", 18);
    SQL> select * from bustour;
    
        BUSSNO START_DATE PASSENGERS
    ---------- ---------- ----------
          4123 04-10-2009         20
          4123 05-10-2009         25
          4123 05-10-2009         18
          4123 06-10-2009         15
          6138 03-10-2009         16
          6138 03-10-2009         19
          6138 04-10-2009         22
          6138 04-10-2009         13
          4123 07-10-2009         23
          4123 08-10-2009         27
          4123 11-10-2009         15
    
        BUSSNO START_DATE PASSENGERS
    ---------- ---------- ----------
          6138 05-10-2009         16
          6138 05-10-2009         13
          6138 05-10-2009         18
          6138 05-10-2009         24
          6138 07-10-2009         20
          6138 08-10-2009         18
    
    17 rows selected.
    
    I want query output as below :
    
    Bussno  start_date      end_Date   totalpassengers   maxpessenger  maxpassdate
    4123    04-10-09        06-10-09          78              25         05-10-09
    6138    03-10-09        04-10-09          70              22         04-10-09 
    4123    07-10-09        11-10-09          65              27         08-10-09
    6138    05-10-09        08-10-09         109              24         05-10-09
    So that we can know on what particular travel calendar, we have obtained maximum passengers and the date. (For calculating % of bonus driver)

    Please help me to write the query.

    Best regards
    Nisha

    OK, something like this:

    with my_tab as (select 1 id, 4123 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 20 passengers from dual union all
                    select 2 id, 4123 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 25 passengers from dual union all
                    select 3 id, 4123 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual union all
                    select 4 id, 4123 busno, to_date('06/10/2009', 'dd/mm/yyyy') start_date, 15 passengers from dual union all
                    select 5 id, 6138 busno, to_date('03/10/2009', 'dd/mm/yyyy') start_date, 16 passengers from dual union all
                    select 6 id, 6138 busno, to_date('03/10/2009', 'dd/mm/yyyy') start_date, 19 passengers from dual union all
                    select 7 id, 6138 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 22 passengers from dual union all
                    select 8 id, 6138 busno, to_date('04/10/2009', 'dd/mm/yyyy') start_date, 13 passengers from dual union all
                    select 9 id, 4123 busno, to_date('07/10/2009', 'dd/mm/yyyy') start_date, 23 passengers from dual union all
                    select 10 id, 4123 busno, to_date('08/10/2009', 'dd/mm/yyyy') start_date, 27 passengers from dual union all
                    select 11 id, 4123 busno, to_date('11/10/2009', 'dd/mm/yyyy') start_date, 15 passengers from dual union all
                    select 12 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 16 passengers from dual union all
                    select 13 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 13 passengers from dual union all
                    select 14 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual union all
                    select 15 id, 6138 busno, to_date('05/10/2009', 'dd/mm/yyyy') start_date, 24 passengers from dual union all
                    select 16 id, 6138 busno, to_date('07/10/2009', 'dd/mm/yyyy') start_date, 20 passengers from dual union all
                    select 17 id, 6138 busno, to_date('08/10/2009', 'dd/mm/yyyy') start_date, 18 passengers from dual)
    -- end of mimicking your data; use SQL below:
    select busno,
           min(start_date) start_date,
           max(start_date) end_date,
           sum(passengers) total_passengers,
           max(passengers) max_passengers,
           max_pass_date
    from   (select id,
                   start_date,
                   busno,
                   passengers,
                   distance,
                   max(start_date) keep (dense_rank first order by passengers desc) over (partition by distance, busno) max_pass_date
            from   (select id,
                           start_date,
                           busno,
                           passengers,
                           -- using tabibitosan method, borrowed from Aketi Jyuuzou
                           dense_rank() over (order by id) -
                              row_number() over (partition by busno order by id) distance
                    from   my_tab))
    group by busno, distance, max_pass_date
    order by min(id)
    
         BUSNO START_DATE END_DATE   TOTAL_PASSENGERS MAX_PASSENGERS MAX_PASS_DATE
    ---------- ---------- ---------- ---------------- -------------- -------------
          4123 04/10/2009 06/10/2009               78             25 05/10/2009
          6138 03/10/2009 04/10/2009               70             22 04/10/2009
          4123 07/10/2009 11/10/2009               65             27 08/10/2009
          6138 05/10/2009 08/10/2009              109             24 05/10/2009   
    
  • Help - run the extended CO query?

    Read the many threads on the topic prior to this announcement, but im still stuck.

    I extended a sowing controller, to display text msgStyle seeded as a link under certain conditions.
    I want to take is:

    If (condition true) {//set the text msg destination uri} otherwise do nothing

    To implement the condition, I have to make a request to check if this value exists in the table. I have not any Vo attached to achieve this.
    I could create a custom VO and attach it to AM programaticaly? One last thing - AM attached to this seeded page is am root.
    I read that AM root should not be extended.

    How can I achieve this?

    Hello

    For this, you can use dynamic VO, create VO, and run the query.

    Kind regards
    Out Sharma

  • Select the format of query results

    SELECT * FROM srm_application_data WHERE application_id = '242564';

    Returns

    app_id question_name data
    ------ ------------- -----
    242564 FirstName qreq
    242564 StaffID 12314
    242564 of State VIC
    242564 o ' Connel of suburbs

    I want that data to be presented as

    First name 242564 qreg staffId 12314 State VIC Subrub o ' Connel

    the path q & d:

     select id
          , wm_concat (name||' '||data)
       from test
      group by id
     ;
    

    as in

    SQL> with test as
      2  (
      3  select 242564 id, 'FirstName' name, 'qreq' data from dual union all
      4  select 242564 id, 'StaffID', '12314'            from dual union all
      5  select 242564 id, 'State', 'VIC'                from dual union all
      6  select 242564 id, 'Suburb', 'o''connel'         from dual
      7   )
      8   select id
      9        , wm_concat (name||' '||data)
     10     from test
     11    group by id
     12   ;
    
            ID
    ----------
    WM_CONCAT(NAME||''||DATA)
    ------------------------------------------------------------------------
        242564
    FirstName qreq,StaffID 12314,State VIC,Suburb o'connel
    
  • LifeCam Cinema: After installing LifeCam 3.0 (many files), no "Microsoft LifeCam" program appears in START / all programs. Looking for a "LifeCam help" on the C drive, no results

    "New hardware found", and "your new hardware is ready to use" I don't know how

    The minimum requirements are met. If by chance, anything to cause a problem, Setup wouldn't let you continue when you went first to install the software.

    Try to install the latest version of the driver package and software Windows XP 32/64 - bit from Microsoft here:
    Let us know after the installation of what is happening,
    Thank you!

    Ryan Thieman
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Number to reach the desired with query result...

    Here some pseudocode tables and data to show my problem:
    CREATE TABLE temp (name_home varchar2(25), name_away varchar2(25), id integer);
    INSERT INTO temp
    VALUES ('a','b',1,1);
    INSERT INTO temp
    VALUES ('c','a',1,3);
    INSERT INTO temp
    VALUES ('e','a',1,4);
    INSERT INTO temp
    VALUES ('c','a',1,6);
    INSERT INTO temp
    VALUES ('d','e',1,5);
    INSERT INTO temp
    VALUES ('b','a',1,7); 
    Desired output of table
            NAME_HOME     NAME_AWAY     ID     SEQ
    
    
         a            b             1     1
            b            a             1     7
         c            a             1     3
         c            a             1     6
         e            a             1     4
         d            e             1     5
    NOTE
    My table contains millions or lines like this, idea would be a solution that would be enough for a table containing millions of combos like those above.


    I want to display the data with the following by order:

    (1) records where any combination of a value of data in "name_home" and "name_away" appears more than one time first (record e.i. with seq 1.7)
    (2) sequence number CSA

    So, for seq 1 and 7, it does not matter to me that 'a' and 'b' switch between name_home and name_away, they must appear first because a combo of a and b in the same record appears more than once and the number of seq of one of the files is smaller than any of the seq in the accounts rendered by 'c' and 'a '. I hope that makes sense.

    Published by: user652714 on November 17, 2010 16:04

    Fixed, when I read until the end :)

    select
    t.*,
    count(*) over(partition by greatest(name_home,name_away),least(name_away,name_home)) cnt,
    first_value(seq) over(partition by greatest(name_home,name_away),least(name_away,name_home) order by seq) min_seq
    from temp t
    order by cnt desc,min_seq asc
    
    NAME_HOME     NAME_AWAY     ID     SEQ     CNT     MIN_SEQ
         a     b     1     1     2     1
         b     a     1     7     2     1
         c     a     1     3     2     3
         c     a     1     6     2     3
         e     a     1     4     1     4
         d     e     1     5     1     5
    

    Kind regards
    Sayan M.

    Published by: xtender on 18.11.2010 11:49

  • run immediately and the set of query results

    Hi gurus,

    I want to create a series of paintings on the fly using run immediately.
    the table_names are stored in another table work_table.


    run immediately (select 'create table' | table_name |) '(id int)' of
    * (select table_name in work_tables)); *


    This will raise error.

    ORA-06550: line 1, column 18:
    PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

    (en) - + new case mod not null < an ID >
    < between double quote delimited identifiers of > < a variable binding >


    instead of using a cursor to run one by one is the lines an alternative solution?

    Thank you very much
    Charles

    May not know why you want to do it in a single statement, anyway:

    SQL> select * from work_tables;
    
    TABLE_NAME
    ------------------------------
    x1
    x2
    
    SQL> declare
      2  str varchar2(32000);
      3  begin
      4    for r in (select table_name from work_tables) loop
      5      str := str || 'execute immediate ''create table ' || r.table_name || '( id int )''; ' ;
      6    end loop;
      7
      8    execute immediate 'begin '||str||' end;';
      9
     10  end;
     11  /
    
    PL/SQL procedure successfully completed.
    
    SQL> desc x1
     Name                                                        Null?    Type
     ----------------------------------------------------------- -------- ------------------------------
     ID                                                                   NUMBER(38)
    
    SQL> desc x2
     Name                                                        Null?    Type
     ----------------------------------------------------------- -------- ------------------------------
     ID                                                                   NUMBER(38)
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 18, 2010 15:03

  • function to return the array of strings, a given string

    Hi all

    someone at - it a procedure/function of relaible, which takes a string like "a |" b | c | d | e' and retrun me a table IE [a, b, c and d, e] so I can loop throug the table and do stuff?

    Cheers in advance

    Concerning

    Satnam

    Hi, Michel,.

    You can loop through the string itself and do things.

    FOR  j IN 1 .. ( LENGTH (txt) -          -- In Oracle 11, use REGEXP_COUNT instead
                          LENGTH (REPLACE ( txt
                          , '|'
                         )
                   )
                ) + 1
    LOOP
         this_item := REGEXP_SUBSTR ( txt
                                , '[^|]+'
                           , 1
                           , j
                           );
         ...
    END LOOP;
    

Maybe you are looking for

  • Envy 15 360 t: adding memory

    I'm considering buying a want, it comes with 8 GB. Video AT hp and DOCS say I must go from the top, remove everything to memory.Is this correct? I have sort of the bottom. There is no access panel.Help please.

  • Hello, I want the YIG oscilloscope with the portable interface so first of all I have to do?

    Hello If I'm portable computer interface with oscilloscope yig so first I have to do? What type of probe is beneficial for me

  • RICHED32. DLL is not a valid Windows image

    I keep getting "RICHED32. DLL is not a valid Windows image"error message.  I use SP3 for XP Professional. The installation disk I have is for sp 1, so I know that I should not reinstall the file from there.  Where can I get this file from. I don't ha

  • How do I know what license key to use.

    I have 3 Windows XP upgrades. I have 2 computers currently XP and I would use my license to get a 3rd operational computer. I don't know which CD, I used to install in two more. How can I activate my 3rd computer. What Cd key to use?

  • QUICKLY out-of-date

    Hello I'm trying to move files and settings over the course of an old installation of XP MCE 2002 SP2 to a new installation of XP Professional SP2. I get an error message indicating that the QUICK version on my old machine is outdated so FAST on my n