title: Using a case column within another case in select clause
body: <p>I have a select clause with a <code>case</code> statement  and I need to create another <code>case</code> statement comparing the column created by the previous <code>case</code> statement. Something like this:</p>
  
  <pre><code>select client
      ,discount
      ,(case when sales_avg&gt;10000 then 30 
          when sales_avg&gt;5000 then 20 
          else 0 end) discount_rule
      ,(case when discount &lt; discount_rule then 1 else 0 end) status 
  from sales;
  </code></pre>
  
  <p>I get a message that <code>discount_rule is unknown</code>. How can I accomplish that?</p>