DB2 - Exemplos simples - GROUP BY



Desenvolvido por DORNELLES Carlos Alberto - Analista de Sistemas - Brasília DF. - cad_cobol@hotmail.com

DB2 - Exemplos simples - GROUP BY

Groups the result set (used with aggregate functions: COUNT, MAX, MIN, SUM, AVG)
Agrupa o conjunto de resultados (usado com funções agregadas: COUNT, MAX, MIN, SUM, AVG)

The following SQL lists the number of customers in each country:
O seguinte SQL lista o CustomerID em cada Country:

    SELECT COUNT(CustomerID)
    ,      Country
      FROM Customers
     GROUP BY Country;

The following SQL lists the number of customers in each country, sorted high to low:
O seguinte SQL lista o CustomerID em cada Country, classificados de cima para baixo (ordem decrescente):

    SELECT COUNT(CustomerID)
    ,      Country
      FROM Customers
     GROUP BY Country
     ORDER BY COUNT(CustomerID) DESC;

Veja também: