I'm looking for something that, given a table like:
| channelid | curveid | xvalue |
| 1 | 21 | 179.9216 |
| 1 | 21 | 180.4314 |
| 1 | 21 | 180.6528 |
| 1 | 21 | 180.9251 |
| 1 | 21 | 181.1334 |
| 1 | 21 | 181.4417 |
| 2 | 21 | 179.9513 |
| 2 | 21 | 180.1612 |
| 2 | 21 | 180.2022 |
| 2 | 21 | 180.8762 |
| 2 | 21 | 181.1331 |
| 2 | 21 | 181.2842 |
| 1 | 22 | 179.9213 |
| 1 | 22 | 180.4415 |
| 1 | 22 | 180.6226 |
| 1 | 22 | 180.9758 |
| 1 | 22 | 181.1639 |
| 1 | 22 | 181.4212 |
| 2 | 22 | 179.9715 |
| 2 | 22 | 180.1513 |
| 2 | 22 | 180.2326 |
| 2 | 22 | 180.8265 |
| 2 | 22 | 181.1437 |
| 2 | 22 | 181.2442 |
returns me the closest xvalue to a value found for each unique channelid curveid combination.
I found this and this. With this I can find the closest value in total. However I need help extending it so it returns the closest to each unique combination.
SELECT * FROM table
WHERE xvalue >= ($myvalue - .5) AND xvalue <= ($myvalue + .5)
ORDER by abs(xvalue - $myvalue)
Thanks!