我有以下表格(表格):
x y
------------------------
3 1
1 4
0 3
0 1
我希望x尽可能低,作为最高优先级,y尽可能低,作为低优先级,我也希望y在某个范围内。 我希望x = 0和y = 3作为输出并执行以下查询:
Select x, MIN(y) AS y
FROM tablea
WHERE x = (SELECT MIN(x) FROM tablea where y between 2 AND 4);
它给了我x = 0和y = 1作为输出(我理解为什么,但我不知道如何修复我的查询以获得我想要的东西)。
答案 0 :(得分:5)
可能最好的方法是
SELECT x, y
FROM tablea
WHERE y BETWEEN 2 AND 4
ORDER BY x, y LIMIT 1
答案 1 :(得分:1)
Select x, MIN(y) AS y
FROM tablea
WHERE x = (SELECT MIN(x) FROM tablea where y between 2 AND 4)
and y between 2 AND 4;