using CASE in the WHERE clause

前端 未结 4 1879
甜味超标
甜味超标 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 09:00

    This is working Oracle example but it should work in MySQL too.

    You are missing smth - see IN after END Replace 'IN' with '=' sign for a single value.

    SELECT empno, ename, job
      FROM scott.emp
     WHERE (CASE WHEN job = 'MANAGER' THEN '1'  
             WHEN job = 'CLERK'   THEN '2' 
             ELSE '0'  END) IN (1, 2)
    

提交回复
热议问题