Get the max of a field in a query of County

Hi, I work with the following SQL query:
WITH ORDERED_QUERY AS
(
SELECT COUNT(SHRTRIT_SBGI_CODE) AS "COUNT OF I",
            SHRTRIT_SBGI_CODE AS "SBGI CODE",
            SHRTRIT_SBGI_DESC AS "INSTITUTION"
FROM SHRTRIT
WHERE (SHRTRIT_SBGI_CODE LIKE 'I%'
GROUP BY SHRTRIT_SBGI_CODE,SHRTRIT_SBGI_DESC
ORDER BY "COUNT OF I" DESC
)
SELECT "COUNT OF I","SBGI CODE","INSTITUTION" 
FROM ORDERED_QUERY
WHERE ROWNUM <= 20
What follows is the table mark code to get a test table:
create table SHRTRIT
(
SBGI_CODE     VARCHAR2(6)     NOT NULL
SBGI_DESC     VARCHAR2(10)
ACTIVITY_DATE     DATE
)
/
INSERT INTO SHRTRIT
(SBGI_CODE,SBGI_DESC,ACTIVITY_DATE)
VALUES
(I08883,MING-CHUAN COLL,10/6/2007 1:47:01 PM)
/
INSERT INTO SHRTRIT
(SBGI_CODE,SBGI_DESC,ACTIVITY_DATE)
VALUES
(I08883,MING-CHUAN COLL,2/10/2009 3:00:14 AM)
/
INSERT INTO SHRTRIT
(SBGI_CODE,SBGI_DESC,ACTIVITY_DATE)
VALUES
(I08883,MING-CHUAN COLL,10/6/2007 12:11:56 PM)
/
INSERT INTO SHRTRIT
(SBGI_CODE,SBGI_DESC,ACTIVITY_DATE)
VALUES
(I08883,MING-CHUAN COLL,2/10/2009 3:00:15 AM)
/
INSERT INTO SHRTRIT
(SBGI_CODE,SBGI_DESC,ACTIVITY_DATE)
VALUES
(I07979,RIYADH TECHNICAL COLLEGE,9/11/2008 3:01:26 AM)
/
INSERT INTO SHRTRIT
(SBGI_CODE,SBGI_DESC,ACTIVITY_DATE)
VALUES
(I07979,RIYADH TECHNICAL COLLEGE,7/6/2010 9:00:02 PM)
/
{CODE}

What I'm trying to do is get the max ACTIVITY_DATE for the institution when it's listed. For example, the max ACTIVITY_DATE for MING-CHUAN COLL is 2/10/2009 3:00:15 AM. The desired output is one record for MING-CHUAN, with a count of 4, the SBGI code, the Institution Name, and the max activity date of 2/10/2009 3:00:15 AM. However, when I just insert MAX(SHRTRIT_ACTIVITY_DATE) as part of the in-line query, it doesn't work like you'd think. It makes separate records for each date, such that here, there would be one record for 2/10/2009 with a count of 2 and one record for 10/6/2007 with a count of 2 for MING-CHUAN. 

It might actually work with this small amount of data, I don't know because I can't make a test table with these few records to find out. It certainly isn't working with the actual table. I know it has something to do with the aggregation, but I'm not quite sure how to get around this problem. I've tried some different things, but none of them have gotten the desired results.

Any help that you might be able to provide would be greatly appreciated!

Thanks so much,
Michelle Craig
Data Coordinator
Admissions operations and transfer services
Kent State University                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

Not exactly what you're trying to do, but:

SQL> SELECT  *
  2    FROM  SHRTRIT
  3  /

SBGI_C SBGI_DESC                      ACTIVITY_DATE
------ ------------------------------ ----------------------
I08883 MING-CHUAN COLL                10/06/2007 01:47:01 pm
I08883 MING-CHUAN COLL                02/10/2009 03:00:14 am
I08883 MING-CHUAN COLL                10/06/2007 12:11:56 pm
I08883 MING-CHUAN COLL                02/10/2009 03:00:15 am
I07979 RIYADH TECHNICAL COLLEGE       09/11/2008 03:01:26 am
I07979 RIYADH TECHNICAL COLLEGE       07/06/2010 09:00:02 pm

6 rows selected.

SQL> WITH ORDERED_QUERY AS (
  2                         SELECT  COUNT(SBGI_CODE) AS "COUNT OF I",
  3                                 SBGI_CODE AS "SBGI CODE",
  4                                 SBGI_DESC AS "INSTITUTION",
  5                                 MAX(ACTIVITY_DATE) LAST_ACTIVITY_DATE
  6                           FROM  SHRTRIT
  7                           WHERE SBGI_CODE LIKE 'I%'
  8                           GROUP BY SBGI_CODE,SBGI_DESC
  9                           ORDER BY "COUNT OF I" DESC
 10                        )
 11  SELECT  "COUNT OF I",
 12          "SBGI CODE",
 13          "INSTITUTION",
 14          LAST_ACTIVITY_DATE
 15    FROM  ORDERED_QUERY
 16    WHERE ROWNUM <= 20
 17  /

COUNT OF I SBGI C INSTITUTION                    LAST_ACTIVITY_DATE
---------- ------ ------------------------------ ----------------------
         4 I08883 MING-CHUAN COLL                02/10/2009 03:00:15 am
         2 I07979 RIYADH TECHNICAL COLLEGE       07/06/2010 09:00:02 pm

SQL> 

SY.

Tags: Database

Similar Questions

  • Get the Max values and average of the different cycles in the single channel

    Hello

    I'm trying to get the Max values and average of the single channel that has different cycles it contains. I tried to use commands such as Chnclasspeak3 and chnpeakfind, but they were not useful for me. What I need is the Max values and average of the different cycles numbers saved in the data channel.

    Exampld if the string contains 5 numbers of repetitive cycles, then we must find the maximum values and the average of these 5 cycles in the single channel. Attached reference data. This is the .raw file and I have the plugin for it to use in diadem 11.1.

    Kind regards

    X. Ignatius

    Hello, Ignatius,.

    Sorry, it took some time to provide a replacement based on the script for the function. Please take a look at the attached script. I changed the script to use my function if the tiara-version is less than 12. My script function is not as fast and more stable than the implementation of tiara, but for now, it does the job

    Andreas

  • How can I get the max of a measurement value

    How can I get the max of a measurement value?

    http://forums.NI.com/T5/LabVIEW/how-can-I-return-the-maximum-value-from-a-voltage-sensor-over/m-p/30...

    I tried the while loop max-min-solution described in this link. But this using my myRio acceleration measurement no longer works. It seems to hang.

    I use the I2C Communication.

    The inner circle while loop is a bad construction.  It will be either executed once, if enter the Boolean value is True, or forever if the value is false.

    Put your records on the timed loop shift and eliminate inside while loop.  Then your code should work.

  • ([JDev12c, ADF] 1) how to get the value of a field of the line currently selected in question 2) af:table: flowScope

    Hallo,

    How can I get the value of a field in the row that is currently selected in an af:table?

    I need to pass this value to a setCurrentRowWithKeyValue who took the record to display in another (by a button) called page:

    Limited workflow

    Page1 - goToPage2-> setCurrentRowWithKeyValue-> PAGE2

    I defined a managed bean flowScope for the workflow in which I created the variable 'CodeToSetPage2Row '.

    I will store the value of the field for the selected line in this variable so that I can move on to the setCurrentRowWithKeyValue.

    Could be this method OK? Ore is there any good practice to achieve this goal?

    The managed bean flowScope used to go to the stubborn task may take some values from the outside?

    The workflow defined will be executed in a dynamic region.

    Thank you

    Federico

    Federico, you cannot use a flow variable scope for this page. The region has no access to the bean. You must use a workflow for this parameter.

    To get an attribute of the currently selected line you make slide data vo of control on the page attribute. This will create a link attribute for this attribute. Once this link exists, switch to source mode and remove the component that you do not want.

    The framework passes the value of the current row in this affair of the attribute (table should be in single selection mode).

    Click on the button, you switch the binding of the attribute for the setting of task flow using a setPropertyListener.

    In the workflow, you call the setCurrentRowWithKeyValue with the parameter of workflow as the default activity.

    Timo

  • [JDev12c, ADF] How to get the value of a field from the selected line in af:table and...

    Hallo,

    I want to double click on a line of an af:table to call a page that displays a form (based on a View object) with the details of the selected line.

    I need to go to the second page the value of a field on the line that is selected on the first page.

    How can I do this? In particular, how can I get the value of a field from the selected line? How can I call the second page on double-click on the af line: table?

    Thank you

    F.

    Why would user, you need to pass a value of the line to the shape?

    The framework selects the line you want to display in the form. All you have to do is to show the form with the selected line. It is the framework automatically as long as you use e vo even the same data control.

    Timo

    Post edited by: Timo Hahn
    And the handling double-clicks is described here http://www.oracle.com/technetwork/developer-tools/adf/learnmore/56-handle-doubleclick-in-table-170924.pdf

  • get the value of two fields in a field

    Hellou,

    I need some new help with javascript

    Currently I use the below code to get the value of one field to another:

    getField("Text35").value = getField("Text1").valueAsString;

    Now, I wonder how to change this code, so I could get the values of two fields in one. I for example field 'Name' and 'name' field, now I want to show in the field 'name '.

    Example, if the firstname field have John value and the value of the lastname field is Doe, I want to show in the field name as "John Doe".

    I hope that u understand what I want

    Thank you for helping me!

    getField("Text35").value = getField("Text1").valueAsString + "" +.

    getField("Text2").valueAsString;

  • How to get the Max value in Essbase

    Hello

    I have problem to get the max value of 3 years in Essbase.
    How can I get the max value of Dec 2009, Dec 2010, Dec 2011.
    Suppose the value of Dec 2009 = 1000, dec 2010 = 1500 and Dec 2011 = 2000
    I want to get the max value of these three value, how can I do this in the Essbase calculation Script.
    Any idea?


    Thank you.

    Kind regards

    Joni

    You did not specify if year and period are there separate dimensions, in any case as always a number of different possbilities and I don't have much time today to think about, but only one method can be to use @MAXRANGE

    DIFFICULTY (other members to set, 'Dec')

    'MemberToStoreAgainst' = @MAXRANGE("MemberToFindMaxRangeFor","2009:"2011");

    ENDFIX

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • How to get the value of a column in sql query?

    Hi, anyone knows how to get the value of a column in sql query?

    Here is my code, the value must be 1350079224397 in my PB, but I get 0

    QString query ("SELECT version FROM db_version");

    QVariant result = sda.execute (query);
    QVariantMap versionMap = result.toList () such () .toMap ();
    If (! versionMap.IsEmpty ())
    {
    qDebug()<"Version: "=""><>
    }

    OK, I have the solution

    QString query ("SELECT version as version FROM db_version");

  • How to get the max of an element value selected iota AF Max.

    Hello community,

    Let me explain the scenario.

    We have a workbook of discoverer, who have several reports. These reports extract information from multiple views built specifically to retrieve information in several tables. So far, quite normal.

    Like any other report you can build these views, you can select the elements (columns) that you will use to create the report. Some of these elements (columns) are selected with the function MAX aggregate for this element; is that to say, instead of the profit of the item, and then click the SUM aggregation function, select the MAX aggregate function. With this option, we can get limit the number of search results.

    In our case, we have created a report that shows the items that we have in our stock, for each item, the report shows the sum of kilograms, the average price, its value (the sum of the average price x kilograms) for each element of the family, and we want the report to display for each item (remember that each element is a line in the report or folder) the largest number of transaction_id (of which there been selected using MAX aggregate function for the selected item), but a kind of transaction types.

    Let's see an example:

    Family | Product name | Sum of the kgs. | Units | Average price | Value of stock. Month | Year | Transaction ID | Type of transaction | Date of movement
    4420 | ALUMINA PS - M BB720 | 97.680,000 | KG | 44737 | 43.699,10 | 04. 10. 7740531 | Finalización Conjunto WIP | 16/12/2009
    4420 | ALUMINA PS - M BB720 | 47.760,000 | KG | 44737 | 21.366,39 | 04. 10. 8100110 | EXCESS | 31/03/2010
    4420 | ALUMINA PS - M BB720 | 97.680,000 | KG | 44737 | 43.699,10 | 04. 10. 8201603 | EXCESS | 30/04/2010

    Considerations:

    The value you see in the Transaction id is the maximum value that the field have; is that to say, each of the types of transactions, it shows the highest (last) transaction that id. looking at the example, the problem now is that we want to pocket the result a llitle little more. We want the report to show only from each product name or transaction id higher, either the date of circulation higher (as in the example above matches the transaction id 8201603 that have the highest movement 30/04/2010 - date).

    I stopped at that point because I don't see how to filter the data to get the result we want.

    Any suggestion or help would be appreciated, cause honestly, I don't see how.

    Thanks in advance.

    Luis.

    Hi Luis
    In order to get the last day of the month, given a year and month as strings, you will need to convert the strings to a date. Assuming you have a two-digit month and, presumably, a 2 digit, with the year 2000 year and more, then you need to start with a date and let's start with the first day of the month like this:

    To_date ('01' |: month: year, 'DDMMYY')

    You can use the ADD_MONTHS function to spend the month by one and then if you subtract 1 from that you will end up with the last day of the month.

    EndofMonth = ADD_MONTHS (TO_DATE ('01' |: month |: year, 'DDMMYY'), 1)-1

    You can also use the LAST_DAY function like this:

    EndofMonth = LAST_DAY (TO_DATE ('01' |: month |: year, 'DDMMYY'))

    Best wishes
    Michael

  • How can I get the position of a field in a Manager?

    Hi all

    I just want to know that how I can the position of a field in a Manager (Vertical or flow)?

    If I get the x, position y, I can do a pop-up screen depends on this position...

    Can someone help me solve this problem?

    Thank you very much.

    Welcome to the forums.

    I use getFocusRect to fetch the XYRect of the target field. You can get the details from there.

  • get the size of a field

    How can HII, I get the height and width of a field?

    as a sidenote: do not set the police in the graphics object. or, if you do, save the old value and return it after calling super.

    You can get the preferredHeight of optimization of resources in iterating through the fields and asking their preferredHeight.

    or you can wait until the layout is complete and just use getHeight

  • How to get the Max value with other columns data also.

    Suppose that a query is covered with the data as

    Time of ID
    01 07/12/2014
    02 07/05/2014
    03 16/07/2014
    04 07/07/2014

    I need to get the ID and time to time max.
    that is, should I get
    Time of ID
    03 16/07/2014

    To do this, I wrote a query that gives me necessary data. But I thought that's the best way?
    Is it an effective way to get this data?
    My query that returns the data required is:

    SELECT ID, MAX_DT FROM
    (
    Select 'DUMMY', ID, TIME1, MAX (TIME1) OVER (PARTITION 'DUMMY') AS MAX_DT FROM TAB1
    WHERE ID IN (BLAH BLAH)
    )
    WHERE MAX_DT = (EDT) 1

    Frank mentioned links


    WITH test_data (id, time) LIKE)

    SELECT 01, to_date('2014/07/12','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 02, to_date('2014/07/16','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 03, to_date('2014/07/16','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 04, to_date('2014/07/07','yyyy-mm-dd') FROM dual

    )

    SELECT id, time

    go (select id,

    time,

    Max (Time) on latest_time (order by time lines between unbounded preceding and following unbounded)

    of test_data

    )

    where time = latest_time

    ID TIME
    3 16/07/2014
    2 16/07/2014

    Concerning

    Etbin

  • How to get the Max of elements of type datetime value

    Hi all
    I wanted to get the last value timestamp (DateTime data type) of the node list. I have the following xml. In this xml file, I want to get the modifydate element that has the last time stamp via xquery/xpath, it should return me following result 2011-09-29 T 17: 21:17 + 10:00

    < CustomerList >
    < CustomerDetails >
    < Name > Test 1 < / name >
    assets of < status > < / status >
    < modifyDate > 2011-08-20T 17: 21:17 + 10:00 < / modifyDate >
    < / CustomerDetails >

    < CustomerDetails >
    < Name > Test 2 < / name >
    Cancel < status > < / status >
    < modifyDate > 2011-08-29T 17: 21:17 + 10:00 < / modifyDate >
    < / CustomerDetails >

    < CustomerDetails >
    < Name > Test 3 < / name >
    assets of < status > < / status >
    < modifyDate > 2011-09-29T 17: 21:17 + 10:00 < / modifyDate >
    < / CustomerDetails >
    < / CustomerList >


    I tried to use the
    CustomerList/CustomerDetails/modifyDate [not (. < =... / the above - sibling:CustomerList/CustomerDetails modifyDate) and not (. < =... / following - sibling:CustomerList/CustomerDetails modifyDate)]
    But it does not work on the datetime data type.
    Any help in this regard is highly appreciated.

    Concerning

    Published by: user6736659 on Sep 5, 2011 06:15

    Hello

    The following XQuery query should give you what you want:

    max(
     for $i in /CustomerList/CustomerDetails/modifyDate
     return xs:dateTime($i)
    )
    

    For example, by using Oracle SQL:

    SQL> var xmldoc varchar2(4000)
    SQL> begin
      2   :xmldoc := '
      3  
      4   Test 1
      5  active
      6  2011-08-20T17:21:17+10:00
      7  
      8
      9  
     10   Test 2
     11  cancel
     12  2011-08-29T17:21:17+10:00
     13  
     14
     15  
     16   Test 3
     17  active
     18  2011-09-29T17:21:17+10:00
     19  
     20  ';
     21  end;
     22  /
    
    PL/SQL procedure successfully completed
    
    SQL> select xmlquery('max(
      2   for $i in /CustomerList/CustomerDetails/modifyDate
      3   return xs:dateTime($i)
      4  )'
      5  passing xmltype(:xmldoc)
      6  returning content
      7  )
      8  from dual
      9  ;
    
    XMLQUERY('MAX(FOR$IIN/CUSTOMER
    --------------------------------------------------------------------------------
     2011-09-29T17:21:17.000000+10:00
     
    
  • Get the max value with other areas

    Hi all

    I have a table as below

    Value name
    - - - - - - - - - - - - - - - -
    A1 5
    A3 10
    A2 7
    A2 9
    A1 10

    What I get is the max (Value) and with the consolidation of its name

    Value name
    - - - - - - - - -
    A2 16

    Thank you
    Alex

    Published by: user8606416 on June 1, 2011 10:17

    Published by: user8606416 on June 1, 2011 10:26

    Depends on how you feel on one of the links of:

    SELECT name, value
    FROM (SELECT name, SUM(value)
          FROM table
          GROUP BY name
          ORDER BY 2 DESC)
    WHERE rownum = 1
    
    SELECT name, SUM(value)
    FROM table
    GROUP BY name
    HAVING SUM(value) >= ALL (SELECT SUM(value)
                              FROM table
                              GROUP BY name)
    

    among many other methods. The first takes a single arbitrary registration in the case of a tie, and the second shows all the related records.

    John

  • How to get the value of a field of flex?

    Hello

    I have a page of the OFA, where flexfield is on the 2nd tab of the page.
    When the page loads, 1 tab loaded. At this point, I want to enter the value in the flex of the 2nd tab type?

    I added this element Flex type using customization on the 2nd tab...

    How to get the value in the field?

    Values Flexfield
    How to get the value Flexfield OAF page Runtime
    Re: Get flexfield value during execution
    Requirement DescritiveFlexField

    Thank you
    -Anil

Maybe you are looking for

  • Satellite Pro A300D-140 - graphic question

    Hi all I wonder if someone can help me. I'm having a lot of problems with my new laptop at the moment, and I'm now about to re - format and reinstall Windows.The question is this: when you browse the Web site with pictures or embedded videos, display

  • How to find the basis of registry and file settings for windows xp

    I need to know how to save registers and settings of a windows XP hard files Bank that has no back/restore cd. Can I simply find restore point files and just copy and paste it on the disc after full format and re-installation of operating system?

  • 7 in 1 card reader

    I recently bought a HP110-430 with a 7 in 1 reader.  I don't know what cards he supports or how to insert my card.

  • How adobe dawnload

    Please help me

  • Update the Table of Adf

    Hi allI have a page jspx, with a table and a button.Create the table data control, and it contains 4 columns(Name, card student, asked (Question or answer)).I create the code for the button to work1. Select a record2 send email3. when I send the requ