title: Using BigQuery to find outliers with standard deviation results combined with WHERE clause
body: <p>Standard deviation analysis can be a useful way to find outliers. Is there a way to incorporate the result of this query (finding the value of the fourth standard deviation away from the mean)...</p>
  
  <pre><code>SELECT (AVG(weight_pounds) + STDDEV(weight_pounds) * 4) as high FROM [publicdata:samples.natality];
  </code></pre>
  
  <p>result = 12.721342001626912</p>
  
  <p>...Into another query that produces information about which states and dates have the most babies born heavier that 4 standard deviations from average?</p>
  
  <pre><code>SELECT state, year, month ,COUNT(*) AS outlier_count
   FROM [publicdata:samples.natality]
  WHERE
    (weight_pounds &gt; 12.721342001626912)
  AND
    (state != '' AND state IS NOT NULL)
  GROUP BY state, year, month 
  ORDER BY outlier_count DESC;
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Row  state   year    month   outlier_count    
  1    MD  1990    12  22   
  2    NY  1989    10  17   
  3    CA  1991    9   14
  </code></pre>
  
  <p>Essentially it would be great to combine this into a single query.</p>