GROUP BY [HAVING]

<< Click to Display Table of Contents >>

Navigation:  Apollo SQL > DDL & DML Statements >

GROUP BY [HAVING]

GROUP BY clause is optional.

HAVING clause is supported.

Field(s) in GROUP BY clause must be present on first columns in SELECT clause.

Examples:

SELECT customer_code, Count(*) AS num_requests,

   SUM(units) AS quantity 

   FROM requests GROUP BY customer_code

 

SELECT date, count(*) AS num_requests FROM requests GROUP BY date

 

SELECT date, SUM(units) AS quantity FROM requests GROUP BY date

 

SELECT date, customer_code, COUNT(*) AS num_requests,

  SUM(units) AS quantity FROM requests GROUP BY date, customer_code

  WHERE date < '1/6/2015'

 

SELECT date, COUNT(*) AS requests, SUM(units) AS subtotal,

  MIN(units) AS minimum, MAX(units) AS maximum, AVG(units) AS average

  FROM requests GROUP BY date

 

SELECT Customer.CustNo, Sum(Orders.AmountPaid), Min(Orders.AmountPaid),

  Max(Orders.AmountPaid), Avg(AmountPaid), Count(*)

  FROM Customer

  INNER JOIN Orders ON (Customer.CustNo = Orders.CustNo)

  GROUP BY Customer.CustNo HAVING Sum(Orders.AmountPaid) > 50000