beliefer commented on a change in pull request #28134: [SPARK-31358][SQL][DOC] 
Document FILTER clauses of aggregate functions in SQL references
URL: https://github.com/apache/spark/pull/28134#discussion_r404136338
 
 

 ##########
 File path: docs/sql-ref-syntax-qry-select-groupby.md
 ##########
 @@ -120,6 +139,31 @@ SELECT id, sum(quantity) AS sum, max(quantity) AS max 
FROM dealer GROUP BY id OR
   |300|13 |8  |
   +---+---+---+
 
+-- Count the number of distinct dealer cities per car_model.
+SELECT car_model, count(DISTINCT city) AS count FROM dealer GROUP BY car_model;
+
+  +------------+-----+
+  |   car_model|count|
+  +------------+-----+
+  | Honda Civic|    3|
+  |   Honda CRV|    2|
+  |Honda Accord|    3|
+  +------------+-----+
+
+-- Sum of only 'Honda Civic' and 'Honda CRV' quantities per dealership.
+SELECT id, sum(quantity) FILTER (
+            WHERE car_model IN ('Honda Civic', 'Honda CRV')
+        ) AS `sum(quantity)` FROM dealer
+    GROUP BY id ORDER BY id;
 
 Review comment:
   ```
   SELECT
        id,
        SUM(quantity) FILTER (WHERE car_model IN ('Honda Civic', 'Honda CRV')) 
AS `sum(quantity)`
   FROM dealer
   GROUP BY id ORDER BY id;
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to