title: Error in executing two groupbys in sparkSQL
body: <p>I am new to sparksql and i was trying to experiment certain queries with that.</p>
  
  <p>This is the query i am trying to execute</p>
  
  <pre><code>sqlContext.sql(SELECT id , category ,AVG(mark) FROM data GROUP BY id, category)
  </code></pre>
  
  <p>I am not getting proper output when i run the query.</p>
  
  <p>instead of actual value of category i am getting some value as 1,2,3.</p>
  
  <p>I am stuck at this weird error for long time</p>
  
  <p>but when i do simple select statement and one group by its working perfectly</p>
  
  <pre><code>sqlContext.sql(SELECT id , category  FROM data)
  
  sqlContext.sql(SELECT id  ,AVG(mark) FROM data GROUP BY id)
  </code></pre>
  
  <p>What is wrong? Does SPARKSQL has something to do with multiple group by.</p>
  
  <p>right now i am running this complex query </p>
  
  <pre><code>sqlContext.sql(SELECT data.id , data.category, AVG(id_avg.met_avg) FROM (SELECT  id, AVG(mark) AS met_avg FROM data GROUP BY id) AS id_avg, data GROUP BY data.category, data.id)
  </code></pre>
  
  <p>This works, but taking a longer time to execute.</p>
  
  <p>Please Help</p>
  
  <p>Sample data:</p>
  
  <pre><code>|id | category | marks  
  | 1 |        a |  40  
  | 2 |        b |  44 
  | 3 |        a |  50  
  | 4 |        b |  40  
  | 1 |        a |  30 
  </code></pre>
  
  <p>The output should be:</p>
  
  <pre><code>|id | category | avg  
  | 1 |        a |  35  
  | 2 |        b |  44 
  | 3 |        a |  50  
  | 4 |        b |  40  
  </code></pre>