title: Group by and order by in Spark SQL
body: <p>I am trying to access s3 data using a spark Application. I am applying Spark SQL to retrieve the data. It is not taking group by clause.</p>
  
  <pre><code>DataFrame summaryQuery=sql.sql("Select score from summary order by updationDate desc);
  summaryQuery.groupBy("sessionId").count().show();
  summaryQuery.show();
  </code></pre>
  
  <p>Also i am trying it directly</p>
  
  <pre><code>    DataFrame summaryQuery=sql.sql("Select score from summary group by sessionId order by updationDate desc);
  summaryquery.show();
  </code></pre>
  
  <p>But in both the cases i am getting SQL exception.</p>
  
  <pre><code>Exception in thread "main" org.apache.spark.sql.AnalysisException: expression 'score' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
  </code></pre>
  
  <p>Please specify how can i query the data.</p>