using CASE in the WHERE clause

前端 未结 4 1875
甜味超标
甜味超标 2021-01-31 08:38

simplified version of my query

SELECT *
FROM logs 
WHERE pw=\'correct\' AND CASE WHEN id<800 THEN success=1 ELSE END 
AND YEAR(timestamp)=2011 
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-31 08:53

    You can transform logical implication A => B to NOT A or B. This is one of the most basic laws of logic. In your case it is something like this:

    SELECT *
    FROM logs 
    WHERE pw='correct' AND (id>=800 OR success=1)  
    AND YEAR(timestamp)=2011
    

    I also transformed NOT id<800 to id>=800, which is also pretty basic.

提交回复
热议问题