解决了!
对于 Value1 = 600 和 Value2 = 1894:
SELECT number,code,(spread2)AS spread FROM(SELECT number,code,@curRow := @curRow + 1 AS RowNumber, (1894 - Limit1) AS spread1,(Limit2 - 1894) AS spread2
FROM MyTable JOIN (SELECT @curRow := 0) r WHERE name="John" AND 600>=L1 AND 600<=L2 AND 1894>=Limit1 AND 1894<=Limit2)temp WHERE RowNumber=1
UNION
SELECT number,code,(spread1)AS spread FROM(SELECT number,code,@curRow := @curRow + 1 AS RowNumber, (1894 - Limit1) AS spread1,(Limit2 - 1894) AS spread2
FROM MyTable JOIN (SELECT @curRow := 0) r WHERE name="John" AND 600>=L1 AND 600<=L2 AND 1894>=Limit1 AND 1894<=Limit2)temp WHERE RowNumber=2
ORDER BY spread DESC limit 1
当 Value1 = 950 且 Value2 = 2400 时:
SELECT number,code,(spread2)AS spread FROM(SELECT number,code,@curRow := @curRow + 1 AS RowNumber,(2400 - Limit1) AS spread1,(Limit2 - 2400) AS spread2
FROM MyTable JOIN (SELECT @curRow := 0) r WHERE name="John" AND 950>=L1 AND 950<=L2 AND 2400>=Limit1 AND 2400<=Limit2)temp WHERE RowNumber=1
UNION
SELECT number,code,(spread1)AS spread FROM(SELECT number,code,@curRow := @curRow + 1 AS RowNumber,(2400 - Limit1) AS spread1,(Limit2 - 2400) AS spread2
FROM MyTable JOIN (SELECT @curRow := 0) r WHERE name="John" AND 950>=L1 AND 950<=L2 AND 2400>=Limit1 AND 2400<=Limit2)temp WHERE RowNumber=2
ORDER BY spread DESC limit 1
结果当我得到一排时它也有效。