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.

Tags: Database

Similar Questions

  • How to choose the textfield values form and calculate

    Treat all

    Urgent please help

    How to choose the textfield values form and calculate totals. IE when clint fill amount textfield other textfields automatically calculate and display values. I am using uninstall.

    Thanks in advance

    My code is more

    < ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional / / IN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > ""

    " < html xmlns =" http://www.w3.org/1999/xhtml ">

    < head >

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

    < title > Untitled Document < /title >

    < / head >

    < body >

    < table width = "400" border = "0" align = "center" cellpadding = "0" cellspacing = "0" >

    < tr >

    < td width = "187" align = "right" valign = "middle" class = "KT_th" > < strong >

    < label for = "amount_gbp" > total (GBP): < / label >

    < / strong > < table >

    < td width = "14" height = "30" > < table >

    < td width = "199" height = "30" > < label >

    < input type = "text" name = "textfield" id = "textfield" / >

    < / label > < table >

    < /tr >

    < tr >

    < td align = "right" valign = "middle" class = "KT_th" > < strong >

    < label for = "admin_char_gbp" > Admin amount (GBP): < / label >

    < / strong > < table >

    < height td = "30" > < table >

    < height td = "30" > < label >

    < input type = "text" name = "textfield3" id = "textfield3" / >

    < / label > < table >

    < /tr >

    < tr >

    < td align = "right" valign = "middle" class = "KT_th" > < strong >

    < label for = "agent_char_gbp" > Agent Charges (GBP): < / label >

    < / strong > < table >

    < height td = "30" > < table >

    < height td = "30" > < label >

    < input type = "text" name = "textfield4" id = "textfield4" / >

    < / label > < table >

    < /tr >

    < tr >

    < td align = "right" valign = "middle" class = "KT_th" > < strong >

    < label for = "total_amount_gbp" > amount Total (GBP): < / label >

    < / strong > < table >

    < height td = "30" > < table >

    < height td = "30" > < label >

    < input type = "text" name = "textfield6" id = "textfield6" / >

    < / label > < table >

    < /tr >

    < tr >

    < td align = "right" valign = "middle" class = "KT_th" > < strong >

    < label for = "total_paid_gbp" > Total paid (GBP): < / label >

    < / strong > < table >

    < height td = "30" > < table >

    < height td = "30" > < label >

    < input type = "text" name = "textfield7" id = "textfield7" / >

    < / label > < table >

    < /tr >

    < tr >

    < td align = "right" valign = "middle" class = "KT_th" > < strong >

    < label for = "balance_gbp" > balance (GBP): < / label >

    < / strong > < table >

    < height td = "30" > < table >

    < height td = "30" > < label >

    < input type = "text" name = "textfield8" id = "textfield8" / >

    < / label > < table >

    < /tr >

    < /table >

    < / body >

    < / html >

    Here´s a pointer which will show you how to set the calculation within a javascript function: dynamically calculate the sum of the fields

    See you soon,.

    Günter

  • How to choose the item value list based on another value of list item

    Hello friends,
    I have two list items named xxx and yyy... OK, my problem is I want to choose a value of yyy list item based on the value of article xxx...

    Example: I select 'Computer' in xxx... Based on this I want to choose the item values in yyy as a monitor, keyboard, mouse, etc... This must be done at run time. How can I do this... Give me a few examples of code [pls tell me trigger appropriate to place this encodings]
    Thanks in advance,
    Battistelli

    Very simple to use the LOV and query of the lov which is attached to the YYY field, use the query as below...

    SELECT columns
    FROM table
    WHERE column_name = :XXX_FIELD
    

    Use the ENTER OF LIST Yes property for the YYY field.

    -Clément

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

  • How to choose the maximum value in a column of a table by using the cursor and iteration

    Hello everyone
    I have a table loan_detail
    and a column inside loan_amount
    now I want to take the values in this table with the cursor, then using iteration that I want to take a max value of him using this slider
    Here is my table
    LOAN_AMOUNT
    
    100
    200
    300
    400
    500
    5600
    700
    I could make using the concepts of single loop, but when I tried to do by using the slider I wasn't able to do.
    Concerning
    Prost

    You can get the maximum value for a particular column in SQL, PLSQL needn't; Always avoid PLSQL so you can do it in SQL. But always as an example:

    declare
    number of Temp: = 0;
    Start
    for news in some loan_amt of loan_detail
    loop
    If (temp
    end if;
    end loop;
    dbms_output.put_line (temp);
    end;

    Edited by: Mahanam January 5, 2011 03:11

  • 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 choose the lowest value of the record

    I would return the lowest bidder of the recording of the same rental date and call number.
      SELECT   v.vendor "Vendor Id", INITCAP (v.vnames) "Vendor Name", B.DATELET "Letting Date" ,d.call "Call Number",
                      TO_CHAR (d.calcbtot, '$99,999,999.99') AS "Bidders Estimate",
                      TO_CHAR (SUM (q.qty * q.price), '$99,999,999.99')
                                                                       AS" Enginers Estimate"          
                    
                 FROM letprop l,
                      proposal p,
                      propitem q,
                      bidlet b,
                      bidtabs c,
                      itemlist i,
                      vendor v,
                      bidders d
                WHERE (l.letting = b.letting)
                  AND b.letting = c.letting
                  AND p.cspecyr = i.ispecyr
                  AND q.prpitem = i.item
                  AND p.contid = l.lcontid
                  AND q.contid = p.contid
                  AND c.vendor = l.avendor
                  AND l.CALL = c.CALL
                  AND q.lineflag = c.lineflag
                  AND q.iplineno = c.iplineno
                  AND l.letting = d.letting
                  AND c.letting = l.letting
                  AND c.CALL = d.CALL
                  AND c.letting = d.letting
                  AND v.vendor = d.vendor
                  AND l.letstat = 'A'
                  AND  b.datelet  between to_date ('2007/01/01', 'yyyy/mm/dd')    AND to_date ('2011/12/31', 'yyyy/mm/dd')
             GROUP BY v.vendor, v.vnames, d.calcbtot, (d.calcbtot / l.contamt), B.DATELET, d.call
             ORDER BY b.datelet, "Bidders Estimate";
    Vendor Id     Vendor Name     Letting Date     Call Number     Bidders Estimate      Enginers Estimate
    K0030              Interstate Improvement Inc     01/26/2007 00:00:00     009         $190,601.40         $209,895.00
    M110               Mankato Electric Inc     01/26/2007 00:00:00     015         $216,790.00         $213,000.00
    C470               Collisys     01/26/2007 00:00:00     015         $222,426.00         $213,000.00
    K110               Killmer Electric Co Inc     01/26/2007 00:00:00     015         $223,386.00         $213,000.00
    E110               Egan Company      01/26/2007 00:00:00     015         $225,740.00         $213,000.00
    G0034              Granite Ledge Electrical Contractors Inc     01/26/2007 00:00:00     015         $226,750.00         $213,000.00
    B500               Carl Bolander & Sons Co     01/26/2007 00:00:00     014         $227,227.00         $274,104.98
    M0069              Mattison Contractors Inc     01/26/2007 00:00:00     014         $231,340.03         $274,104.98
    T0041              Three Rivers Construction Inc     01/26/2007 00:00:00     014         $237,623.00         $274,104.98
    M110               Mankato Electric Inc     01/26/2007 00:00:00     012         $238,971.20         $253,700.00
    R290               Ridgedale Electric Inc     01/26/2007 00:00:00     015         $247,900.00         $213,000.00
    desired out put is this one.
    
    K0030              Interstate Improvement Inc     01/26/2007 00:00:00     009         $190,601.40         $209,895.00
    M110               Mankato Electric Inc     01/26/2007 00:00:00     015         $216,790.00         $213,000.00
    B500               Carl Bolander & Sons Co     01/26/2007 00:00:00     014         $227,227.00         $274,104.98

    Maybe this? I used the dense rank as if two bidders have bid even then both of them will be selected. If you just want one, replace it with row_number()

    SELECT * FROM (
    SELECT v.vendor "Vendor Id",
           INITCAP (v.vnames) "Vendor Name",
           B.DATELET "Letting Date",
           d.CALL "Call Number",
           TO_CHAR ( d.calcbtot, '$99,999,999.99') AS "Bidders Estimate",
           TO_CHAR ( SUM (q.qty * q.price), '$99,999,999.99')
             AS " Enginers Estimate",
           DENSE_RANK ()
           OVER (
             PARTITION BY v.vendor,
                          v.vnames,
                          d.calcbtot,
                          (d.calcbtot / l.contamt),
                          B.DATELET,
                          d.CALL
             ORDER BY TO_CHAR ( d.calcbtot, '$99,999,999.99') ASC
           )
             RN
      FROM letprop l,
           proposal P,
           propitem q,
           bidlet b,
           bidtabs c,
           itemlist i,
           vendor v,
           bidders d
     WHERE (l.letting = b.letting)
       AND b.letting = c.letting
       AND P.cspecyr = i.ispecyr
       AND q.prpitem = i.item
       AND P.contid = l.lcontid
       AND q.contid = P.contid
       AND c.vendor = l.avendor
       AND l.CALL = c.CALL
       AND q.lineflag = c.lineflag
       AND q.iplineno = c.iplineno
       AND l.letting = d.letting
       AND c.letting = l.letting
       AND c.CALL = d.CALL
       AND c.letting = d.letting
       AND v.vendor = d.vendor
       AND l.letstat = 'A'
       AND b.datelet BETWEEN TO_DATE ( '2007/01/01', 'yyyy/mm/dd') AND TO_DATE ( '2011/12/31', 'yyyy/mm/dd')
    GROUP BY v.vendor,
             v.vnames,
             d.calcbtot,
             (d.calcbtot / l.contamt),
             B.DATELET,
             d.CALL
    ORDER BY b.datelet, "Bidders Estimate") where rn=1
    

    G.

  • How to choose the value of a string are numeric together and words of letters (for example, TEST)

    Hi all

    How to choose the value of a string are letters (for example, TEST) and all numeric...

    for example
    TEST 123456
    TEST 34567
    123456 ABCD
    1234 TEST
    TESTING 12345
    TEST 1@234$
    YOUR T 123456

    I want the results of the query as below.
    TEST 123456
    TEST 34567

    And I tried to use regexp_like in this case but without success. See the code below.
    SELECT * FROM TABLE WHERE regexp_like (Description, ' [TEST] % & [[: digit:]] + $');

    How can I do this, please answer.

    Thank you

    WF

    If you want to return only the rows that contain the string 'TEST', followed by zero or more space characters, followed by one or more digits?

    How about this:

    SELECT *.

    FROM my_table

    WHERE REGEXP_LIKE(description,'^TEST\s*\d+$')

  • 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

  • How to choose the display by default when you use two screens on my Mac Pro?

    How to choose the display by default when you use two screens on my Mac Pro?

    The default view when you have several is made that you drag the little icon in the menu bar in this pane:

    .

  • When you export (share) a project, how to choose the thumbnail of the freeze frame which restores the clip?

    I just shared (exported) a project that is a simple take a clip for a friend who has downloaded on its website. The problem is that, when the video ends by playing on his site, he returned to a freeze frame that seems completely random and is not the image I want. How to choose the exact image that the video will return as "thumbnail by default?"

    Thank you

    Kevin

    Cannot set lla at the FCC. Many layout site Web apps will allow you to set the poster frame for the video files.

  • How to choose the download location? download automatically to the users in c drive folder. I want to change it... Please help me...

    How to choose the download location? download automatically to the users in c drive folder... I want to change my office... Please help me out...

    Tools-> Options-> save-> click on the Browse button and find the folder where you want to save the files.

Maybe you are looking for

  • Mobile access point does not

    Well, I'll do that, nice and simple. Since the upgrade to the marshmallow on my Moto X pure on Verizon, I was not able to use my Mobile Hotspot. When I allow it, it reads just "Turning hot spot..." "it turns on but it never broadcasts the network nam

  • How do I cleaning system files after transfer to the new iMac?

    Recently I transferred data from an old iMac (2008 version) to a new iMac (screen Retina 4 k) and know that the old system files, extensions and structure have been transferred.  Is there a software out there program that can scan the system/program

  • Support of the shared Variables in the third part XP embedded based of PTC?

    I sent a request in an embedded XP touch function (third party). The application works very well, but hosted on a RT (sbRIO Board) shared variables are not getting updated in the app on PTC 1. the PTC is part of the project as a Windows XP Embedded T

  • Windows Mail cannot open attachments

    I am running vista Home premium SP2 and using Windows mail. Two days ago I can't display all the attachments of my emails. If I double click to open them - there is no answer. If I try to save, I get "cannot run command '. I can see if I send to anot

  • What is in my HP_Recovery drive (D :) I don't see?

    Hi, when I click on properties of my HP_REVOVERY disk (D :), I find that 4.48 GB of memory is used and 950 MB is available. However, when I click on drive D: real to see what I have here, I find that there is only the recovery file that is only 185 K