For example, I have 2 tables like this
For every row in table 1, I want to get the row with
same
customer id
andnearest
date
(in my case,table2.date < table1.date
)
The result should look like this
How can I do this in SQL? I tried to search, but didn't find many things related. and what if I want to change the condition to <=
, >=
or >
?
Thanks!
Note:
- please using standard SQL, as I'm not using PostgreSQL
- If I can use Python, I might simply get away with a for-loop.