cancel
Showing results for 
Search instead for 
Did you mean: 

Friday night SQL script blues

0 Kudos
1,183

A table has the following columns (amongst others)

Transaction_ID

Type

Debit

Credit

Nominal_Code

Log_Time

All rows are posted in pairs (Debit = value and Credit = 0) and (Debit = 0 and Credit = value) so the log-time should be the same for both rows

I'm trying to return records where

Type = 'BR' or 'BP' and Nominal_Code is the same for both the first and second rows (and all subsequent pairs)...

I'm struggling to think of a way to returning those values, probably based on the log-time being the same for the two rows

Might have over complicated that description (it's Friday). Really returning any records where Nominal_Code is the same for any two rows that have the same log_time is the bit that's confusing me.

Any ideas?

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

Breck_Carter
Participant

This has NOT been tested...

SELECT "***** t1 columns: ',
       t1.*,
       "***** t2 columns: ',
       t2.* 
  FROM t AS t1
          INNER JOIN t AS t2
                  ON t1.Transaction_ID <> t2.Transaction_ID
                 AND t1.Log_Time       =  t2.Log_Time
                 AND t1.Nominal_Code   =  t2.Nominal_Code
 ORDER BY t1.Log_Time;