SQL/MX Quick Start (G06.24+, H06.03+)

Displaying Information About Groups of Rows
HP NonStop SQL/MX Quick Start523724-002
4-4
Counting Rows
Counting Rows
Use the COUNT(*) function to count the rows in a group. Use the COUNT function with
a selected column to count the values of that column in a group.
Example
Count the number of orders for each sales representative. Use COUNT(*) to specify
that you want to count the number of rows in each group:
SELECT SALESREP, COUNT(*)
FROM ORDERS
GROUP BY SALESREP
ORDER BY SALESREP;
Some of the selected rows are:
Sales/Rep (EXPR)
--------- ------------------
220 3
... ...
226 3
... ...
568 1
--- 9 row(s) selected.
Example
Count the number of customers who have one or more orders placed with each sales
representative:
SELECT SALESREP, COUNT(DISTINCT CUSTNUM)
FROM ORDERS
GROUP BY SALESREP
ORDER BY 2 DESC;
Some of the selected rows are:
Sales/Rep (EXPR)
-------- ------------------
220 3
... ...
226 2
... ...
568 1
--- 9 row(s) selected.