在子查询之间但不包括在内

时间:2013-04-27 18:00:13

标签: mysql between

我在使用日期时看到了对此的回复,但没有查看子查询。我有以下

SELECT  *
FROM  `TEST` 
where `ID` BETWEEN
(SELECT `ID`  FROM `TEST` WHERE `Home_Team`
REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
order by ID asc LIMIT 1)
AND 
(SELECT `ID` FROM `TEST` WHERE `Home_Team`
REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
order by ID asc LIMIT 1,1) 

我希望结果不具有包容性。不幸的是,我没有任何运气与< > =

2 个答案:

答案 0 :(得分:2)

最好我知道,a BETWEEN b and cb <= a and a <= c的语法糖,即总是包容性的。要使其独占,请将其重写为b < a and a < c

答案 1 :(得分:0)

ID是整数吗?如果是这样,只需+1-1

SELECT  *
FROM  `TEST` 
where `ID` BETWEEN
(SELECT `ID`  FROM `TEST` WHERE `Home_Team`
REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
order by ID asc LIMIT 1) + 1
AND 
(SELECT `ID` FROM `TEST` WHERE `Home_Team`
REGEXP 'saturday|sunday|monday|tuesday|wednesday|thursday|friday' 
order by ID asc LIMIT 1,1) - 1