MySQL使用带有AND子句的BETWEEN子句& OR条款

时间:2013-02-27 06:31:16

标签: mysql sql between

我想运行一个查询,您可以在其中选择 date1 date2 之间的所有数据,其状态为已确认保留< / em>按状态分组。

但是我正在尝试的代码,

select * from reservation where (date(bdate) between '2013-2-4' and '2013-2-8') and status='Reserved' or status='Confirmed' order by status

似乎不起作用。

我需要仅在具有已确认保留状态的日期范围内获取数据。请帮我。感谢。

2 个答案:

答案 0 :(得分:1)

select *
from   reservation 
where  date(bdate) between '2013-2-4' and '2013-2-8' and 
       status IN ('Reserved','Confirmed')
order  by status

答案 1 :(得分:0)

你可以使用这样的查询

select *
from reservation
where date(bdate) between '2013-2-4' and '2013-2-8'
    and (status = 'Reserved'
      or status = 'Confirmed')
order by status