This table consists of transaction data, where each row is one transaction exchange. Main data to collect: average amount of years it takes users to switch from checks to credit cards when paying.
I'm trying to subtract the year a person first used a check with the year he first used a credit card to the same receiving bank account. Example data is attached below. This query is freaking complicated and I'm wondering if I should/can even do this, but this is what I got so far
SELECT
ID,
BankAcc#,
FROM table
GROUP BY
ID,
BankAcc#,
TransYear,
Method
ORDER BY
ID,BackAcc#,TransYear ASC
Example table (sorry couldn't embed the photo since I'm new)
My idea was to group ID-Bank#-TransYear-Method into a single row, with the TransYear being the earliest year of that Method, by using ORDER BY ASC LIMIT 1. Problems I'm running into:
- Oracle doesn't support LIMIT after the ORDER BY clause. I tried using OFFSET or FETCH but it didn't work for some reason after the ORDER BY clause. I have Oracle 12.9.0.71 so I theoretically should have that function, but nope. I also tried WHERE rownum=1 but it limits all my results to 1 instead of limiting the ID-Bank-Year-Method group to 1.
- Even if I do manage to get rows of the correct data, I still don't know how I can subtract the year values of check against card. Issue is that the data is in the same column and I need to distinguish it with another column before subtracting the year values.
Any thoughts? Appreciate any help, especially since this is really complicated.