没办法,其实你可以写成函数,把逻辑写到函数里,where后面直接加这个函数就可以了,这样虽然不能优化,但是把逻辑和条件分开了,希望对你有帮助
select * from (select * From 用户 where (布防时间thetime)unionselect * From 用户 where 撤防时间<布防时间 and 布防时间>thetimeunionselect * From 用户 where 撤防时间<布防时间 and 撤防时间)x where x.ID=Str(UsrID)
子查询