Select the MAX value

My goal here is to select the id of the half of the class more recently taken for a given student. Are the session id in the format (1, yy, 2/5/7 - spring, and autumn)-, 2004 summer semester would be 1045. A half of 1095 ID would be newer than that of 1042.

I wrote the following, but it doesn't quite know how I want it. He returned several lines where ideally he doesn't return a single line. I tried to limit 1 and some other things around him, but I always get an error whenever I try to run that. I also tried to add ' where rowcount < 2 "but this 1045 statements, not 1095. I think it gets the number of rows before it does the calculation of MAX.

Any ideas?
select MAX(grades.semester_id)
from grades
join requirements
on (grades.COURSE_ID=requirements.COURSE_ID)
where requirements.CERT_ID = '1'
and student_id = '0000006'
group by grades.course_id

Hello

Try this:

SELECT grades.semester_id
  FROM grades
  JOIN requirements ON (grades.COURSE_ID = requirements.COURSE_ID)
 WHERE requirements.CERT_ID = '1'
   AND student_id = '0000006'
   AND rownum <= 1
 ORDER BY grades.semester_id DESC

Kind regards

Tags: Database

Similar Questions

  • by selecting the max value of the rank function.

    Hi I have the following querry on the table use:

    Select user_id, e-mail,
    Rank() (PARTITION BY Email order by user_id) AS rank_l
    of users_tab;

    It gives me the result as follows:
    user_id E-mail rank_l
    1 1 [email protected]
    2 2 [email protected]
    3 [email protected] 1
    4 [email protected] 2
    5 [email protected] 1
    6 [email protected] 2
    7 [email protected] 3

    I need to select the user rank max id from the result set.
    in this case, the result should I get is:
    user_id E-mail rank_l
    2 2 [email protected]
    4 [email protected] 2
    7 [email protected] 3


    Help, please?

    Hello

    The "with" clause is only for the purppose test, use your own data. The solution is in the OLAP NTH_value function.

    select
    distinct
    nth_value(user_id,1) over (partition by email order by user_id desc) as id,
    nth_value(email,1) over (partition by email order by user_id  desc) as email
    from users_tab
    order by 1
    

    It works with your own data?

    Kind regards.

  • Find the max value

    Hi team,

    I have the following query where I need to find the max value

    [code]

    with t as)

    Select 'L1' R_nm, R_Data 'Data', 'Obj' R_Obj, r_prec 'Wd', '2' double val

    Union of all the

    Select 'L1', 'Data', 'Obj', 'No', '4' double

    Union of all the

    Select 'L2', 'Data', 'Obj', 'No', '4' double)

    Select t.*, max (val) on rk (partition r_nm, r_data, r_obj) of t

    [/ code]

    My results should be

    [code]

    r_nm r_data r_obj r_prec rk val

    L1 Data Obj 1 2 Wd

    L1 data Obj 4 No.2

    L2 Data Yes 1 1 Obj

    [/ code]

    Thank you


    Hello

    It seems that you are not interested in the MAX at all.  Looks like you want to classify the lines, such as one that has the lowest value is assigned the number 1, the 2nd line with the lowest values gets 2,... and line with him gets N-th lowest value N.  If is not serious if the MAX is 4, 2 or 420.

    Here's a way to do it:

    SELECT T.*

    , RANK () OVER (PARTITION BY r_nm, r_obj)

    ORDER BY val

    ) AS rk

    T

    ORDER BY r_nm, r_obj

    val

    ;

    Depending on how you want to deal with links, you can use ROW_NUMBER or DENSE_RANK instead of RANK.

  • 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

  • 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 to select the default value for a choice of selection when page.jsff load

    Hello everyone, I am newbie have little problem

    I have problem with soc (selectOneChoice)
    in this case I ' to select the default value of af: SelectOneChoice (select first selectItem) when the page is finished loading

    < af:selectOneChoice label = "" Jenny Bahan: "id = 'soc1'"
    autoSubmit = 'true '.
    valueChangeListener = "#{WHStockSetReleaseBean.cekJenisBahan} '"
    Binding = "#{WHStockSetReleaseBean.v_jenisBahan}" >
    * < af:selectItem label = "GBB" value = "GBB" id = "si2" / > * = > i'want to select this value for the default (select first selectItem)
    < af:selectItem label = "GBP" value = "GBP" id = "si1" / >
    < / af:selectOneChoice >

    If someone help me to solve this problem

    THX
    agungdmt

    Hello

    try to set the attribute value to af:selectOneChoice like that.

    
    

    Kind regards
    Sicard.

  • 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/

  • Get the MAX value of dimension 2 table

    I have a little trouble to find a value MAX (or MIN) of the second dimension in a 2-dimensional array. I do a query and the first dimension is the column name, the second is the values. I'm coming out of the MAX value of the column in the second dimension. ArrayMax said "the array passed cannot contain more than one dimension."

    Any ideas? I'm sure that this is possible.

    MaxValue = ArrayMax (QueryName ["FieldName"]);

    or Q of Q.

  • SQL, find the MAX value and placing it as a QVariant

    I have a database that is loaded and defines the customerID as 0 which is ideal when the database is not be saved and restored, etc.  The question I have is that I added the possibility to users to restore a backup in the app, and now I have to do a query to select MAX (customerID) so that there is no duplicate CustomerID when you add or save items.  Here is the following code, I knew that I must settle, specifically the 0 highlighted in red.  I need zero to be the new customerID max value:

    int SettingsStorage::load(int& lastID, GroupDataModel *model)
    {
        // number of locations loaded.
        QSettings settings(m_author, m_appName);
        int loadedCount = 0;
    
        QVariant items;
        // Get the last customer id first.
        // ID's will be generated by incrementing this number
        // Note values coming from settings should be cast to the
        // required type.
         lastID = settings.value(m_lastCustomerIDKey, 0).toInt();
        items = m_sda->execute("SELECT * from items ORDER BY datefield");
        qDebug()<< "the ID" << items;
        // Load all the locations from the database.
        foreach( const QVariant& temp, items.value() ) {
            Location *p;
            if (loadLocation(temp.value(), p)) {
                model->insert(p);
                loadedCount++;
            }
        }
        return loadedCount;
    }
    

    Ive tried the following, but it doesn't seem to do anything:

    int SettingsStorage::load(int& lastID, GroupDataModel *model)
    {
        // number of locations loaded.
        QSettings settings(m_author, m_appName);
        int loadedCount = 0;
    
        QVariant items;
        // Get the last customer id first.
        // ID's will be generated by incrementing this number
        // Note values coming from settings should be cast to the
        // required type.
         QVariant endID = m_sda->execute("Select MAX(customerID) from items")
         lastID = settings.value(m_lastCustomerIDKey, endID).toInt();
        items = m_sda->execute("SELECT * from items ORDER BY datefield");
        qDebug()<< "the ID" << items;
        // Load all the locations from the database.
        foreach( const QVariant& temp, items.value() ) {
            Location *p;
            if (loadLocation(temp.value(), p)) {
                model->insert(p);
                loadedCount++;
            }
        }
        return loadedCount;
    }
    

    Any help will be loved and marked solutions.

    -Thanks in advance

    I was wrong about executeAndWait(). Somehow, I decided that you use the SqlConnection object, but seems his SqlDataAccess. So disregard my previous post. Keep your execute method, but you must change your code to something like this:

    QVariant endID = m_sda->execute("select max(customerID) as m from items");
    
    QVariantList vlist = endID.value();
    QVariantMap vmap = vlist.first().toMap();
    
    lastID = vmap["m"].toInt(&ok);
    

    So I changed your SQL query slightly and added "that m" so I will have something to refer later.

    Then I cast QVariantList because it is where are the results.

    Then because we know its going to be the only record, I took the 1st element in the list and converted to QVariantMap.

    Last step is to get the maximum.

    Should work this time

  • Update based on the max value of different tables.

    {code}

    create the table rule_table (number rule_id);

    insert into rule_table values (10);

    insert into rule_table values (20);

    insert into rule_table values (30);

    insert into rule_table values (40);

    create the table auth_table (number of auth_id, rule_id number);

    insert into auth_table values (1000, 10);

    insert into auth_table values (2000, 10);

    insert into auth_table values (3000, 10);

    insert into auth_table values (4000, 20);

    insert into auth_table values (5000, 20);

    insert into auth_table values (6000, 30);

    insert into auth_table values (7000, 30);

    insert into auth_table values (8000, 40);

    insert into auth_table values (9000, 40);

    create the table pay_table (pay_id number, auth_id number, pay_indicator number);

    insert into pay_table values (11111, 1000, 0);

    insert into pay_table values (22222, 1000, 1);

    insert into pay_table values (33333, 1000, 0);

    insert into pay_table values (44444, 2000, 0);

    insert into pay_table values (55555, 2000, 1).

    insert into pay_table values (66666, 2000, 0);

    insert into pay_table values (77777, 3000, 0);

    insert into pay_table values (88888, 3000, 0);

    insert into pay_table values (99999, 4000, 0);

    insert into pay_table values (111111, 4000, 0);

    insert into pay_table values (222222, 5000, 0);

    insert into pay_table values (333333, 5000, 0);

    insert into pay_table values (444444, 6000, 0);

    insert into pay_table values (555555, 7000, 1);

    insert into pay_table values (666666, 8000, 0);

    insert into pay_table values (777777, 9000, 0);

    insert into pay_table values (888888, 9000, 1);

    create the table rule_pay (rule_id number, pay_max_indicator number);

    insert into rule_pay values (10, 0);

    insert into rule_pay (20, 0) values;

    insert into rule_pay (30, 0) values;

    insert into rule_pay (40, 0) values;

    {code}

    My intention is:

    for every find of rule_id on the maximum pay_indicator (tables 3 query to get the max Show pay_indicator below) and on the other table I have to update this value max based on rule_id.

    with max_tab

    as

    (

    Select a.rule_id, max (pay_indicator) pay_indicator

    rule_table a.,

    b auth_table,

    c pay_table

    where a.rule_id = b.rule_id

    and b.auth_id = c.auth_id

    A.rule_id group

    )

    Update rule_pay

    Set pay_max_indicator = (select max_tab.pay_indicator

    of max_tab

    where max_tab.rule_id = rule_pay.rule_id)

    where

    rule_id in (select rule_id from max_tab);

    The above query does not.

    Any help or suggestions are greatly appreciated.

    Something like that?

    SQL > select * from rule_pay;

    RULE_ID PAY_MAX_INDICATOR

    -------------------- --------------------

    10                    0

    20                    0

    30                    0

    40                    0

    SQL > fusion in rule_pay PR

    2. using (select a.rule_id, max (pay_indicator) pay_indicator

    rule_table 3A,

    auth_table 4 b,

    pay_table 5 c

    6 where a.rule_id = b.rule_id

    7 and b.auth_id = c.auth_id

    Group 8 by a.rule_id

    9        ) u

    10 on (u.rule_id = rp.rule_id)

    11 when matched, then update

    12 set rp.pay_max_indicator = u.pay_indicator

    13;

    4 lines merged.

    SQL > select * from rule_pay;

    RULE_ID PAY_MAX_INDICATOR

    -------------------- --------------------

    10                    1

    20                    0

    30                    1

    40                    1

    BTW, you can't put a WITH clause before an update.  It can only precede a select statement.

  • Select the new value from a line in a group of

    I would like on the following query select the value of the new_cost of the column that belongs to the line with the new date in the column m.creation_date, instead of using max (new_cost)
    select s.segment1, segment2, m.organization_id, sum(primary_quantity), max(new_cost)
    from inv.mtl_material_transactions m, inv.mtl_system_items_b s
    where s.segment2 = 1000435
    and m.organization_id = 83
    and s.organization_id = 136
    and m.inventory_item_id = s.inventory_item_id
    group by s.segment1, s.segment2, m.organization_id 
    order by s.segment1, s.segment2, m.organization_id 
    for example, the following table I would choose the new_cost of the line with creation date 20/08/2010 14:37 (line 4)

    SEGMENT1 SEGMENT2 ORGANIZATION_ID PRIMARY_QUANTITY NEW_COST CREATION_DATE
    1 1000435 83 0,66668 175.500 06/04/2010 16:41
    1 1000435 83 1 189.106 22/06/2010-11:54
    1 1000435 83 - 0, 58333 189.106 2010-07-19 11:55
    1 1000435 83 1 198.459 20/08/2010 14:37
    1 1000435 83 - 0, 5 189.106 08/11/2010 18:12

    Hello

    Another way is to use the FIRST aggregation or the LAST function:

    select    s.segment1, segment2, m.organization_id, sum(primary_quantity)
    ,       MAX (new_cost) KEEP (DENSE_RANK LAST ORDER BY m.creation_date NULLS FIRST)     AS latest_new_cost
    from        inv.mtl_material_transactions       m
    ,        inv.mtl_system_items_b       s
    where       s.segment2          = 1000435
    and        m.organization_id     = 83
    and       s.organization_id     = 136
    and       m.inventory_item_id     = s.inventory_item_id
    group by  s.segment1, s.segment2, m.organization_id
    order by  s.segment1, s.segment2, m.organization_id
    ;
    

    MAX (new_cost) tells what to do in the case of a tie (where two or more lines in the same group have same latest date_creation). MAX means taking the biggest contenders. If these links are impossible to your table, then it does not matter if you say MAX or MIN it.

  • How to display the max value of channel report repel?

    Hi all

    I have 2 text boxes start and ready target on my report. I need my minimum value of the layer and the other value to automatically display in the start menu and to target channels max case respectively.

    How can I go about it?

    Rsh

    Hello, RSH,.

    Now, how can I limit the decimal points to 2 digits, say, for example, we use d.dd. How can I use it here?

    You can simply convert the string variables and the format of this string using the str function in DIAdem.

    Here is an example for your specific application:

    Maximum: @@str (CMax("[1]/Speed"), "d.dd").

    I hope this helps.

    Otmar

  • How to choose the max value

    Hi all

    I have the following data

    Pat_id Pat_enc_csn_id Dept_id Admit_date

    Z269466457982980405500116/05/2014 13:21
    Z0062455957760008205505008/05/2014 14:37
    Z0062455957760008205507608/05/2014-21:06

    My requirement is to get the max dept or the date of maximum admission for each patient. my output should therefore

    Pat_id Pat_enc_csn_id Dept_id Admit_date

    Z269466457982980405500116/05/2014 13:21
    Z0062455957760008205507608/05/2014-21:06

    can someone help me with the code please. using 11 g.

    (Note: there are several number of patients not only 2)

    Thank you.

    with t as)

    Select p,

    ROW_NUMBER() over (partition by Pat_id of Admit_date desc order) rn

    from your_table p

    )

    Select Pat_id,

    Pat_enc_csn_id,

    Dept_id,

    Admit_date

    t

    where rn = 1

    /

    SY.

  • How can I get the color picker to select the hexadecimal value by default?

    Hello world!

    I've upgraded to Photoshop CC 2015, and now when the color picker appears, it selects only the value of C (cynan) by default, which is useless. How can I move it back so the Hex value is selected by default?

    Thanks in advance for any help!

    Ah! I have it. If I open a new file and select the CMYK mode, C is highlighted.

    If I open a new file and select RGB, I get the Hex field highlighted.

    Gene

  • How to find the max value of scrollV in AS3?

    I used the response from Ned to get my 3 fields of scrolling text set based on the value of one of them. Thanks Ned!

    The other two text fields scroll to match the text box 'parent', but in the end – you get to the last scroll position - the other two do not update and 3 text fields are out of alignment. It's just at the end of the roll. The rest of the scroll values line up. I think that if I can find the scrollV max value, I can force the two others to scroll one last time when this value is reached by the text field "parent".

    The textfield object has a property for this: maxScrollV.

Maybe you are looking for