Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Usage » Summarizing, Grouping, and Sorting Query Results » Understanding GROUP BY

Using GROUP BY with multiple columns Next Page

WHERE clause and GROUP BY

You can use a WHERE clause in a statement with GROUP BY. The WHERE clause is evaluated before the GROUP BY clause. Rows that do not satisfy the conditions in the WHERE clause are eliminated before any grouping is done. Here is an example:

SELECT  Name, AVG( UnitPrice )
   FROM Products
   WHERE ID > 400
   GROUP BY Name;

Only the rows with ID values of more than 400 are included in the groups that are used to produce the query results.


The following query illustrates the use of WHERE, GROUP BY, and HAVING clauses in one query:

SELECT Name, SUM( Quantity )
   FROM Products
   WHERE Name LIKE '%shirt%'
   GROUP BY Name
   HAVING SUM( Quantity ) > 100;
name SUM(Products.Quantity)

Tee Shirt


In this example: