I’m new to SQL, and I can’t seem to find this answered anywhere else. I’m working on a project that requires me to convert between two different grids, which has been fairly straightforward in Excel. I have 2 tables of these forms (filled in first few rows for reference):
JDAY TL1 TL2 TL3
1.5 148.2 147.3 146.4
2.5 150.2 150.1 150.0
3.5 151.1 150.7 150.3
Layer Elevation
2 150.9
3 149.9
4 148.9
5 147.9
6 146.9
7 145.9
In Table1, the values under TL1, TL2, TL3 are elevations that will correspond to the Elevation column in Table2. I want to output a view like this:
JDAY TL1 TL2 TL3
1.5 5 6 7
2.5 3 3 3
3.5 2 3 3
I need to search for the nearest less than elevation in Table2 for each value in Table1, and ouput the corresponding Layer number. I’m not sure how to do this since the elevations aren’t exact matches. This works well using the vlookup() function in Excel. Another thing to note is that this is a small piece of the data…there are actually 15 TL columns and 365 JDAY values.
Given the small number of rows involved the following could work: