Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Consecutive records prior to current record

Consecutive records prior to current record

Consecutive records prior to current record

Hello, I have following dataset and need assistance with query to meet the following requirements:

1 1 11/1 C A
2 1 1/3 C A
3 1 1/5 C D
4 1 3/6 C A
5 1 3/7 C A
21 2 1/3 C A
25 2 3/2 C A
27 2 3/10 C A
29 3 2/01 C D
31 3 2/02 D A
40 3 2/05 C A

-For each paymentkey, I would like to get a count of consecutive records prior to curent PAYMENTKEY where PAYMETHOD = C and RESPONSE = A.
-Prior records has to be within 60 days from the same customerkey.
-Only interested in consecutive records since the last D (denied) response. So if there was payment with response of D 1 day before, then consecutive record would be 0. Don't care about anything prior to D (if there is a D response).

Results would be following:
Paymentkey ConsecutiveCount
1 0
2 1
3 2
4 0
5 1
21 0
25 1
27 1 (has to be within 60 days)
29 0
31 0
40 1


RE: Consecutive records prior to current record

01     1     11/01     C     A
02     1     01/03     C     A
03     1     01/05     C     D
04     1     03/06     C     A
05     1     03/07     C     A
21     2     01/03     C     A
25     2     03/02     C     A
27     2     03/10     C     A
29     3     02/01     C     D
31     3     02/02     D     A
40     3     02/05     C     A

RE: Consecutive records prior to current record

To align your data use tag [pre]

01              1     11/01     C         A 
02              1     01/03     C         A
03              1     01/05     C         D   
04              1     03/06     C         A 
05              1     03/07     C         A 
21              2     01/03     C         A 
25              2     03/02     C         A 
27              2     03/10     C         A 
29              3     02/01     C         D 
31              3     02/02     D         A 
40              3     02/05     C         A 


Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: Consecutive records prior to current record

You have ordered your data in some sort of sequence. This is not the way that it is stored in Oracle. You have imposed an order on your data, some sort sequence. So, build a CURSOR to read the data, with an ORDER BY clause. Then FETCH each row checking for a D, when you find a D, continue to FETCH records and do your counting until you hit your end condition.

adaptive uber info galaxies (bigger, better, faster than agile big data clouds)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close