我正在尝试获取上值小于/等于给定值的 ID。
myTable
(`ID`, `Lower`, `Upper`)
(1, 1, 9),
(2, 10, 49),
(3, 50, 99),
(4, 100, 499),
(5, 500, 999),
(6, 1000, 4999),
(7, 5000, 9999);
我试过了:
SELECT ID
FROM myTable
WHERE Lower>=3 AND Upper<=3;
和
SELECT ID
FROM myTable
WHERE Upper<=3
ORDER BY ID DESC;
和
SELECT ID
FROM myTable
GROUP BY ID HAVING MAX(Upper)<=3
ORDER BY MAX(Upper);
和
SELECT *
FROM myTable t1
WHERE t1.Upper <= (
SELECT (MAX(t2.Upper))
FROM myTable t2
);
所有这些都返回空行。
选项:
SELECT ID
FROM myTable
WHERE Upper<=10
ORDER BY ID DESC;
适用于测试值大于 9...
任何人都可以提出一个可行的解决方案吗?