title: How to use case in where clause
body: <p>I want to get only <em>status = 1</em> records. But I don't have status column in my table. So I derived the value using <strong>CASE... WHEN... THEN</strong>. But when I try to use case in where clause, It shows syntax error.   </p>
  
  <p>my query</p>
  
  <pre><code>SELECT SQL_CALC_FOUND_ROWS *,
      CASE
          WHEN quantity &gt; num_used AND (CURDATE() BETWEEN coupon_start_date AND coupon_end_date) THEN '1'
          ELSE '0'
      END AS STATUS
  FROM
      table_coupon_code
  WHERE
      (CASE
          WHEN quantity &gt; num_used AND (CURDATE() BETWEEN coupon_start_date AND coupon_end_date) THEN '1'
          ELSE '0'
      END AS STATUS) = '1' AND coupon_status &lt;&gt; '2'
  </code></pre>
  
  <p>How can I do this ?</p>