Download SQL/MX Quick Start - Hewlett Packard Enterprise Support Center
Transcript
Displaying Information About Groups of Rows 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 --------220 ... 226 ... 568 (EXPR) -----------------3 ... 3 ... 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 -------220 ... 226 ... 568 (EXPR) -----------------3 ... 2 ... 1 --- 9 row(s) selected. HP NonStop SQL/MX Quick Start—523724-002 4 -4