huaxingao commented on a change in pull request #27283: [SPARK-30574][DOC] 
Document GROUP BY Clause of SELECT statement in SQL Reference.
URL: https://github.com/apache/spark/pull/27283#discussion_r368360778
 
 

 ##########
 File path: docs/sql-ref-syntax-qry-select-groupby.md
 ##########
 @@ -18,5 +18,206 @@ license: |
   See the License for the specific language governing permissions and
   limitations under the License.
 ---
+The <code>GROUP BY</code> clause is used to group the rows based on a set of 
specified grouping expressions and compute aggregations on 
+the group of rows based on one or more specified aggregate functions. Spark 
also supports advanced aggregations to do multiple 
+aggregations for the same input record set via `GROUPING SETS`, `CUBE`, 
`ROLLUP` clauses.
 
-**This page is under construction**
+### Syntax
+{% highlight sql %}
+GROUP BY [ GROUPING SETS grouping_sets ] group_expression [ , group_expression 
[ , ... ] ]
+    [ ( WITH ROLLUP | WITH CUBE | GROUPING SETS grouping_sets ) ) ]
+{% endhighlight %}
+
+### Parameters
+<dl>
+  <dt><code><em>GROUPING SETS</em></code></dt>
+  <dd>
+    Groups the rows for each subset of the expressions specified in the 
grouping sets. For example, 
+    <code>GROUP BY GROUPING SETS (warehouse, product)</code> is semantically 
equivalent
+    to union of results of <code>GROUP BY warehouse</code> and <code>GROUP BY 
product</code>. This clause
+    is a short-hand to using an <code>UNION ALL</code> where each leg of the 
<code>UNION ALL</code> 
+    operator performs aggregation of subset of the columns specified in the 
<code>GROUPING SETS</code> clause.
+  </dd>
+  <dt><code><em>grouping_sets</em></code></dt>
+  <dd>
+    Specifies one of more groupings based on which the <code>GROUP BY</code> 
clause performs aggregations. A grouping
+    set is specified by a list of comma separated expressions in 
parenthses.<br><br>
+    <b>Syntax:</b>
+      <code>
+        (() | (expression [ , ...]))
+      </code>
+  </dd>
+  <dt><code><em>grouping_expression</em></code></dt>
+  <dd>
+    Specifies the crieteria based on which the rows are grouped together. A 
grouping expression may be a column alias,
+    a column position or an expression.
+  </dd>
+  <dt><code><em>ROLLUP</em></code></dt>
+  <dd>
+    Specifies multiple levels of aggregations in a single statement. This 
clause is used to compute aggregations 
+    based on multiple grouping sets. <code>ROLLUP</code> is a short-hand for 
<code>GROUPING SETS</code>. For example,
+    GROUP BY warehouse, product  WITH ROLLUP is equivalent to GROUP BY 
warehouse, product GROUPING SETS ((warehouse, product), (warehouse), ()).
+    The N elements of a <code>ROLLUP</code> specification results in N+1 
<code>GROUPING SETS</code>.
+  </dd>
+  <dt><code><em>CUBE</em></code></dt>
+  <dd>
+    <code>CUBE</code> clause is used to perform aggregations based on 
combination of grouping columns specified in the 
+    <code>GROUP BY</code> clause. For example, <code>GROUP BY warehouse, 
product  WITH CUBE</code> is equivalent 
+    to GROUP BY warehouse, product GROUPING SETS ((warehouse, product), 
(warehouse), (product), ()).
+    The N elements of a <code>CUBE</code> specification results in 2^N 
<code>GROUPING SETS</code>.
+  </dd>
+</dl>
+
+### Examples
+{% highlight sql %}
+CREATE TABLE dealer (id INT, city STRING, car_model STRING, quantity INT);
+INSERT INTO dealer  VALUES (100, 'Fremont', 'Honda Civic', 10),
 
 Review comment:
   There is an extra space between ```dealer``` and   ```VALUES```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to