title: Equivalent of defining local variables in SQL
body: <p>I have a table like:</p>
  
  <pre><code>id    B       C
  a     0.5     10.1
  b     0.6     2.3
  c     0.9     2.1
  d     15.2    8.2
  </code></pre>
  
  <p>And I would like to calculate a quantity like: "the standard deviation of the C for which B is below the average".</p>
  
  <p>And I don't know how to do that. </p>
  
  <pre><code>select ssdev_pop(C) from (select B, C from table where B &lt; avg(B) );
  </code></pre>
  
  <p>Doesn't work, and I don't know how to access to avg(B) in one go (I know I could calculate it and plug it into a second query but I want to avoid that).</p>
  
  <p>Can somebody help?  </p>