title: SQL query using GROUP BY with standard deviation?
body: <p>I am having some issues with the standard deviation function (stddev_samp in MonetDB specifically). I tried the following queries without success:</p>
  
  <pre><code>    select industry, avg(marketcap) as industryavg, stddev_samp(marketcap) as industrysd from cumulativeview group by industry
      select  stddev_samp(marketcap) as industrysd from cumulativeview group by industry
  </code></pre>
  
  <p>Each gives me a very weird exception and it seems the stddev function does not work on a group by subset, however using the avg function alone seems to work just fine on a group by subset as in the following query:</p>
  
  <pre><code>    select industry, avg(marketcap) as industryavg  from cumulativeview group by industry
  </code></pre>
  
  <p>And the standard deviation function works just fine when i use a where clause instead of a group by:</p>
  
  <pre><code>    select  stddev_samp(marketcap) as industrysd from cumulativeview where industry='Diversified Investments'
  </code></pre>
  
  <p>Is there an alternate way to write a query that would give me the average and standard deviation for each industry all at once rather than having to go through and write a seperate query for each industry? I am very confused as to why the average function works with group by and stddev does not...</p>