How to get the last transaction in a row in SQL Developer?

What syntax would I use to get the last transaction of a row in SQL developer?
The way I have my query set-up currently it is not returning the correct data, here is my current syntax:
select ssn, max(tran_id), chng_type,tran_id
from pda_tran
where ssn = 'xxx-xxx-0011'
and chng_type = 'C'
group by ssn, chng_type,tran_id;
It returns a 'C' chng_type but it is not the last one. when I query on this ssn this is what I get:
ssn tran_id chng_type
xxx-xxx-0011 001 A
xxx-xxx-0011 002 E
xxx-xxx-0011 003 C
xxx-xxx-0011 004 S
xxx-xxx-0011 005 C
xxx-xxx-0011 006 T
I only want to return the ssn's with a last transaction chng_type of 'C'. How can I get the correct information returned. Please advise.

From what I see and read... there is one to many group by
You wrote
select ssn, max(tran_id), chng_type,tran_id
from pda_tran
where ssn = 'xxx-xxx-0011'
and chng_type = 'C'
group by ssn, chng_type,tran_id;
If you want the max(tran_id), remove it from the "group by"
select ssn, chng_type, max(tran_id)
FROM
(SELECT 'xxx-xxx-0011' ssn, '001' tran_id, 'A' chng_type FROM DUAL UNION
SELECT 'xxx-xxx-0011' ssn, '002' tran_id, 'E' chng_type FROM DUAL UNION
SELECT 'xxx-xxx-0011' ssn, '003' tran_id, 'C' chng_type FROM DUAL UNION
SELECT 'xxx-xxx-0011' ssn, '004' tran_id, 'S' chng_type FROM DUAL UNION
SELECT 'xxx-xxx-0011' ssn, '005' tran_id, 'C' chng_type FROM DUAL UNION
SELECT 'xxx-xxx-0011' ssn, '006'tran_id, 'T' chng_type FROM DUAL )
where ssn = 'xxx-xxx-0011'
and chng_type = 'C'
group by ssn, chng_type;

Similar Messages

  • How to get the last (max of string) row with multiple records for same ID

    Hi all,
    I have a query that returns for each client ID the telephone nr, mobile phone nr, email etc... 
    There is also a column FLG_DEFAULT that indicates if the phone is the default one or not (N= changed).
    Basically what I would like my query to return is the phone number where FLG_DEFAULT = N, if this number is NULL or if FLG_DEFAULT =N does not exist I want to return the phone nr from DEFAULT_FLG = Y.
    Anyone know how I can do this in SQL? I cannot get a maximum because the format is string (e.g. +32/xxx xx xx or xxx/xx xxx xx.
    Thanks!

    ;With cte As
    (Select ClientID, PhoneNumber,
    Row_Number() Over(Partition By ClientID,
    Order By Case When FLG_DEFAULT = 'N' And PhoneNumber Is Not Null Then 1
    When DEFAULT_FLG - 'Y' Then 2 End) As rn
    From YourTableName)
    Select ClientID, PhoneNumber
    From cte
    Where rn = 1;
    Replace column names and table name with your column names and table name.
    Tom

  • How to get the last day of the week?

    Hii
    i can get the calender week number for any given date using
    SELECT to_char(to_date('04/04/2011','MM/DD/YYYY'),'WW') FROM dual
    can any body tell me, how to get the last day of that week ?
    and the answer should be 04/08/2011(8th april )
    thanks
    San
    Edited by: sandeep9 on Apr 4, 2011 3:50 AM

    Hi, San,
    Here's one way:
    WITH     sample_data     AS
         SELECT  DATE '2011-04-04'     AS dt
         FROM     dual
    SELECT  dt
    ,     TO_CHAR (dt, 'WW')     AS week_num
    ,     NEXT_DAY ( dt - 1
               , TO_CHAR ( TRUNC (dt, 'YEAR') - 1
                      , 'Day'
               )          AS end_o_week
    FROM     sample_data;Another way is to use date arrithmetic:
    WITH     sample_data     AS
         SELECT  DATE '2011-04-09'     AS dt
         FROM     dual
    SELECT  dt
    ,     TO_CHAR (dt, 'WW')     AS week_num
    ,     TRUNC (dt, 'YEAR')
          + (7 * CEIL ( (dt - (TRUNC (dt, 'YEAR') - 1))
                / 7
          - 1               AS using_date_arithmetic
    FROM     sample_data;

  • How to get the last day of a month?

    HI,
    I want to know how to get the last day of a month.
    In my JClient form, I tried to get it by using oracle.sql.Date method, that is:
    lastday=oracle.sql.Date anydate.lastDayOfMonth();
    But it does not work. The result is lastday=anydate.
    Why?
    Stephen

    You can use the Calender class...
    Calendar c = Calendar.getInstance();
    and then something like...
    c.add(c.MONTH, 1);
    int dayOfMonth = c.get(Calender.MONTH);
    c.add(c.DAY_OF_MONTH, - (dayOfMonth-1) );
    other usefull functions are:
    System.out.println(" YEAR : " + c.get(Calendar.YEAR));
    System.out.println(" MONTH : " + c.get(Calendar.MONTH));
    System.out.println(" DAY_OF_MONTH : " + c.get(Calendar.DAY_OF_MONTH));
    System.out.println(" DAY_OF_WEEK : " + c.get(Calendar.DAY_OF_WEEK));
    System.out.println(" DAY_OF_YEAR : " + c.get(Calendar.DAY_OF_YEAR));
    System.out.println(" WEEK_OF_YEAR : " + c.get(Calendar.WEEK_OF_YEAR));
    System.out.println(" WEEK_OF_MONTH : " + c.get(Calendar.WEEK_OF_MONTH));
    System.out.println(" DAY_OF_WEEK_IN_MONTH : " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println(" HOUR : " + c.get(Calendar.HOUR));
    System.out.println(" AM_PM : " + c.get(Calendar.AM_PM));
    System.out.println(" HOUR_OF_DAY (24-hour): " + c.get(Calendar.HOUR_OF_DAY));
    System.out.println(" MINUTE : " + c.get(Calendar.MINUTE));
    System.out.println(" SECOND : " + c.get(Calendar.SECOND));
    System.out.println();*/

  • How to get the last day according to fiscal period input in selection scree

    Hello expert
    how to get the last day of fiscal period input.
    the fiscal period inculdes 1-16
    when fiscal period is greater than 12, only calculate the last day of 12nd month
    your solution will be apprecaited, FM existing?
    thank you
    Kevin

    Hi,
    when you give a particular date in any month
    the following fm will give you the last date of that month
    here you can give
    R_FDATE-HIGH  as 01 and month as the period you wnat and year for current year
    concatenates '01'  month year  into r_fdate-high separated by '.'.
    then it will give g_ltdt for that month and year which wil be the last date of that month
        CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
          EXPORTING
            DAY_IN            = R_FDATE-HIGH
          IMPORTING
            LAST_DAY_OF_MONTH = G_LTDT
          EXCEPTIONS
            DAY_IN_NO_DATE    = 1
            OTHERS            = 2.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    thanks & regards,
    Venkatesh

  • How to get the last error for while loop?

    How to get the last error for while loop? I just want transfer the last error for while loop, but the program use the shift register shift all error every cycle.

    What do you mean by "get" and "transfer"?
    If the shift register is not what you want, use a plan tunnel instead.
    Typically, programmers are interested in the first, not last, error.
    Can you show us your code so we have a better idea what you are trying to?
    LabVIEW Champion . Do more with less code and in less time .

  • How to get the last version of flash in MSI format automatically?

    How to get the last version of flash in MSI format automatically?
    Roberto Neigenfind
    Bravo Tecnologia
    www.bravotecnologia.com.br

    Hi Barbara,
    Flash Professional CS5.5 is a 32-bit application which can be installed on computers with either 32-bit or 64-bit operating systems.
    You can purchase this by Adobe's backward Licensing policy :
    " Adobe allows program members to order a current-version license but use a prior version. These members can contact Adobe Customer Service to request a serial number for the earlier version if they do not already have one. Prior-version software is available via ESD and can be purchased through standard resellers. The program member must follow all guidelines of the current-version EULA. "
    Please check the doc : http://www.adobe.com/volume-licensing/policies.html

  • How to get the "last changed by" for a set of function modules?

    How to get the "last changed by" for a set of function modules?
    is there any table to get it??

    See [this|Re: Date of creation of function module] I posted earlier.
    >TFDIR will give you the name of the function group program and the include number.
    >E.g. SAPLZFUNCGROUP Include 01.
    >From this you can construct the include name: LZFUNCGROUPU01.
    >You can look this up in TRDIR to find the creation date (CDAT) of the function module.
    In your case, you need unam and udat.
    matt

  • How to get the last page  SAP Script form

    How to get the last page  SAP Script form.
    I want to print a specific information in the last page of SAP form (Script). Please tell me how to get the last page number.
    Regards

    Hi
    You have to check the system variable &NEXTPAGE&, if it's 0 it means you're in the last page.
    From SAP Help:
    This symbol is used to print the number of the following page. The output format is the same as with &PAGE& .
    Note that on the last page of the output, in each window that is not of type MAIN, &NEXTPAGE& has the value 0.
    /: IF &NEXTPAGE& = '0'
       Last page
    /: ENDIF
    Max

  • How to get the current transaction variant ?

    dear guru,
    could you please tell me how to get the current transaction variant?
    i tried the following method:
      DATA l_tcvariant TYPE tcvariant.
      CALL 'DY_GET_TX_VARIANT'
         ID 'VARIANT' FIELD l_tcvariant.
    but it failed.
    best regards.
    zj

    Try something like this
    DATA:  VARIANT LIKE SHDTVCIU-TCVARIANT.
      CLEAR VARIANT.
      CALL FUNCTION 'RS_HDSYS_GET_TC_VARIANT'
       IMPORTING
         TCVARIANT                     = VARIANT
    *     FLAG_CLIENT_INDEPENDENT       =
    *     RC                            =
    *   TABLES
    *     T_SCREEN_VARIANTS             =
    *     T_INACTIVE_FUNCTIONS          =

  • How to get the last wbs which is displayed  in transaction code cj03?

    Dear Experts,
       I want to get the last wbs which are displayed in  transaction code cj03, i have written below program,but i found it is incorrect. because the sort of wbs  in cj03 is not equal to table prps. the last wbs in cj03  is not equal to table prps.
    who can tell me how to get last wbs which is displayed in cj03?
      SELECT
         PRPS~STUFE
         PRPS~POSID
         PROJ~POST1
         INTO CORRESPONDING FIELDS OF TABLE WA_PRPS_TEMP FROM PRPS INNER JOIN PROJ ON PROJPSPNR = PRPSPSPHI
         WHERE PROJ~PSPID EQ P_PROJECT.
      WA_TLINE = LINES( WA_PRPS_TEMP ).
      READ TABLE WA_PRPS_TEMP INDEX WA_TLINE.
      IF WA_PRPS_TEMP-POSID = P_lastWBS.
        P_LAST = 1
    endif.
    Best Regards,
    Merry

    Hi Merry  ,
      The WBS elements are stored in the table PRPS , so please try using the conversion exit and use the data in internal format then use it in the IF condition.
    Check the FM CONVERSION_EXIT_ABPSN_INPUT and CONVERSION_EXIT_ABPSN_OUTPUT
    Regards,
    Arun

  • How to get the last inserted Autoincrement value in Java for Pervasive DB

    Hi, I need to get the last inserted auto incremented value after the record is inserted IN JAVA For ex. consider we have 4 columns for the myTable in the PERVASIVE DATABASE V10 autoid - identity column (auto increment column) userID userName pageID insertSqlExpression = insert into myTable (userID , userName, pageID) values( ? ,? ,?); prepareInsert = connection.prepareStatement(insertSqlExpression); prepareInsert .excuteUpdate; After inserting the new record how can I get the autoid value (last inserted value) in the Java. Please help me.
    Thanks in advance. Arthik

    JavaArthikBabu wrote:
    I dont have privileges to write new stored procedures in database.I need to do in the Java side only. In many databases that irrelevant. The same way you would do it in a proc can be done with the correctly conceived statement (singular.)
    For ex &#150; if we insert and then the select record's identity value as a single transaction and would this guarantee that what is returned by the select would not include inserts that another might have made?Please do not take that path unless you are absolutely certain that your database does not support any other way to do it.

  • How to get the last revision quote to SSRS report

    HI,
    My report current result like this
    Qoute ID
    Revision
    Q1
    1
    Q1
    2
    Q1
    3
    Q2
    1
    Q3
    1
    I would like to filter if the quote ID is same , only get the last revision quote into report
    Qoute ID
    Revision
    Q1
    3
    Q2
    1
    Q3
    1
    How can i compare the Quote ID and Revision in fetchxml or dataset filter ?
    Thank You

    <fetch distinct='false' mapping='logical' aggregate='true'> 
        <entity name='Quote'> 
           <attribute name='revisionnumber' alias='estimatedvalue_max' aggregate='max' /> 
           <attribute name='quotenumber' alias='quoteid' groupby='true' /> 
        </entity> 
    </fetch>"
    Regards, Saad

  • How to get the Last cell in HSSFCell (Excel sheet)

    Hello
    I am trying to convert an excel sheet to a tab limited file.
    I am using HSSF and unable to track how do i know if the cell encountered is a last filled cell in excel sheet
    Some of the cells in the sheet can be blank. In that case i am just using inputting a '\t' for that cell and read the next one. But coz of this when i get the last cell, a tab is included for that too.
    Can someone let me know how can i rectify this?
    it seems like HSSFCell does not have any methos like lastCell or so
    Thanx

    then use getLastCellNum() in org.apache.poi.hssf.usermodel.HSSFRow

  • How to Get the last data dymanic

    in my bussiness scenarios,I have a cube store some data by month
    but some material have no records in some month
    I need to check if this month have records,get it
    or if there is no records, get the last records by month
    how can i do this?

    You check in R3...whether you have material data for that month...if yopu have data, in BW, run a repair full request by giving this criteria i.e. month criteria.
    Thanks...
    Shambhu

Maybe you are looking for

  • Strange nop(?) code in java.awt.Dialog

    Can anyone give some explanation for the following code? private void hideAndDisposeHandler() {     if (keepBlocking) {         synchronized (getTreeLock()) {             keepBlocking = false;             EventQueue.invokeLater(new Runnable(){ public

  • . How to put Check box in every row in Table

    Hi Friends, I have one doubt in Webdynpro with java. How to put Check box in every row in Table? For Exam My requirement is I am getting BAPI from ECC System. So I have to go given input details in first view and output details in SecondView. So in S

  • Motion menus

    Hi, I'm having trouble with motion menus and buttons in DVD SP 2.0. They set up ok, but do not play in the simulator - both menu and buttons are black! If only one menu is assigned motion, it will play once, but revert to black when motion buttons ar

  • My iPhone4 Refuses to update or Restore!!!

    My iPhone4 Refuses to update or Restore Error appears No. 10 As in the following image: http://store3.up-00.com/Jun11/bAQ60064.png

  • How to move iphotos from one user to another?

    Hi, I inherited my sister's computer and have her iphoto album under her user, and my iphoto album under my user. I would like to import a large number of photos from her iphoto to mine. how do I do it? Thanks, Katarina