MySQL介于Statement和> =< =>之间<不工作

时间:2016-05-24 21:57:46

标签: mysql

我无法让我的声明工作,我可以让AND EffectiveDate >= '2015-06-01'工作,只要我添加另一个日期条件就会中断。我尝试使用CAST('2015-06-01' AS DATE)但没有成功,我也尝试使用'2015-06-01 00:00:00'日期变体,但没有成功。

SELECT 
    ID, 
    Division, 
    EffectiveDate, 
    PM, 
    case Status 
        when 0 then 'Dead'
        when 1 then 'Active'
        when 2 then 'Job'
        when 3 then 'Pending'
        when 4 then 'Sales Lead'
        when 5 then 'Budget'
        when 6 then 'Change Order'
    end as Status, 
    Name, 
    Address, 
    ProjectType,
    sellPrice
FROM intranet.t_bidinfo
WHERE Division = 'TI'
    AND Status = 2 OR Status = 6
    AND EffectiveDate BETWEEN '2015-06-01' AND '2015-06-30'
ORDER BY EffectiveDate ASC
;

1 个答案:

答案 0 :(得分:1)

查询的一个问题是OR的优先级低于ANDEffectiveDate上的条件不适用于具有Division ='TI'的行 和状态= 2.

你可能想写

AND (Status = 2 OR Status = 6)

或等同地

AND Status IN (2, 6)