This query started talking about transaction codes and now it appears to be about an account. There probably needs to be an inner join of 2 streams of data selected from the original. The first stream identifies accounts for which a TQ is present and the second stream is the other transactions (subject to being not too old) The join is on account number. The date of the TQ transaction acts like an opening-date. The output of the join generates multiple rows per account number. However it seems the requested shape is one row per account with columns for each transaction thpe. It is not obvious whether there might be multiple transaction for each transaction type, nor how to handle that. If the data are unique by transaction type within each account, a transpose is needed. However for non-unique, deduplication needs to have rules defined.
... View more