Itβs hard to explain, so Iβll break it ... Here is the goal
Suppose you have a table
ID | Weight 1 2 2 4 3 8 4 66 5 11 6 44 7 33
And let me have a set of interested identifiers, say (3,4)
My goal is to get two other lines (one for each of the two interested identifiers), so that the line corresponding to the interested identifier has a weight that is one level less than the weight of the identifier of interest
therefore in this case
for id 3, we want to return a line with identifier 2 and weight 4, since line id 2 is the first line whose weight (4) is less than the weight of line id 3 (8)
for id 4, we want to return a line with id 6 and weight 44, since line id 6 is the first line whose weight (44) is less than the weight of line id 4 (66)
How would you do this with mysql in one query, in which we use the IN () notation for interested identifiers .....
source share