0 Replies Latest reply: Nov 1, 2012 10:07 AM by 855114 RSS

    Got a doubt in SQL

    855114
      Hi someone help me to write this query....

      Here is the data;

      Se.No     Case Number     p-start-date     P-Type     P-status     P-status-date
      1     1     01011999     A     AE     01011999
      1     1     01011999     A     LP     01011999
      1     1     01011999     A     PE     01011999
      2     2     01012000     A     AE     01012000
      2     2     01012000     A     LP     01012000
      2     2     01012000     A     Kl     01012000
      3     2     01012000     B     DC     01012000
      3     2     01012000     B     AE     01012000
      3     2     01012000     B     Kl     01012000
      4     3     01012001     A     CN     01012001
      4     3     01012001     A     AE     01012001
      4     3     01012001     A     PE     01012001
      4     3     01012001     A     PE     01012001
      4     3     01012001     A     Kl     01012001

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

      Hi This is how data looks now what i need is, If with in a group PE exists i need p-status date of the status which imdtly follows last PE, or else if PE doesnt exists in a group then p-status date of status which imdtly follows AE.

      Can any one help me to write query in sql... please only sql not in plsql.

      Thanks

      Edited by: 852111 on Nov 1, 2012 8:07 AM