I've got two tables that look something like this:
Table 1:
Unit Date
A 9/30/17
B 9/30/17
Table 2:
Unit Date Metric
A 9/30/17 100
A 6/30/17 250
A 5/31/17 150
B 8/15/17 200
B 4/30/17 150
B 4/15/17 100
For each combination of Unit and Date from Table 1, I want to pull back the corresponding Metric value from Table 2. If there is not a match in Table 2, I want to pull back the Metric value for the next closest date that is < the date from Table 1. Using the examples above, I would expect to get 100 for Unit A and 200 for Unit B.
How can I get this into query form? I've been having a hard time wrapping my head around it. It would be easy if I was just dealing with dates, but the Unit component is what's throwing me off.