我有以下查询,它通常有效,并且应该返回涵盖定义时间范围的所有行(如果没有绝对匹配,则取最接近的前一行和下一行 - 在http://www.orafaq.com/node/1834中概述)
SELECT * FROM table
WHERE id=__ID__ AND `date` BETWEEN
IFNULL((SELECT MAX(`date`) FROM table WHERE id=__ID__ AND `date`<=__LOWERLIMIT__), 0)
AND
IFNULL((SELECT MIN(`date`) FROM table WHERE id=__ID__ AND `date`>=__UPPERLIMIT__), UNIX_TIMESTAMP())
ORDER BY `date`
但希望通过引用外部选择来减少两个表子选择,但显然它不喜欢它
SELECT * FROM (SELECT * FROM table WHERE id=__ID__) b
WHERE `date` BETWEEN
IFNULL((SELECT MAX(`date`) FROM b WHERE `date`<=__LOWERLIMIT__), 0)
AND
IFNULL((SELECT MIN(`date`) FROM b WHERE `date`>=__UPPERLIMIT__), UNIX_TIMESTAMP())
ORDER BY `date`
有没有办法在没有三个表选择的情况下进行查询?