In this section: |
The COUNT command counts the number of instances that exist for a specified field. The COUNT command is particularly useful combined with the BY phrase, which is discussed in Sorting Tabular Reports.
COUNT counts the instances of data contained in a report, not the data values.
For COUNT syntax, see How to Use Display Commands in a Request.
By default, a COUNT field is a five-digit integer. You can reformat it using the COMPUTE command, and change its field length using the SET COUNTWIDTH parameter. For details about the COMPUTE command, see Creating Temporary Fields. For information about SET COUNTWIDTH, see the Developing Reporting Applications manual.
When COUNT is used in a request, the word COUNT is appended to the default column title, unless the column title is changed with an AS phrase.
To determine how many employees are in the EMPLOYEE data source, you can count the instances of EMP_ID, the employee identification number.
TABLE FILE EMPLOYEE COUNT EMP_ID END
The following shows the output of the request.
EMP_ID |
COUNT |
------ |
12 |
To count the instances of EMP_ID for each department, use this request:
TABLE FILE EMPLOYEE COUNT EMP_ID BY DEPARTMENT END
The following shows the output of the request indicating that of the 12 EMP_IDs in the data source, six are from the MIS department and six are from the PRODUCTION department:
EMP_ID DEPARTMENT COUNT ---------- ------ MIS 6 PRODUCTION 6
The following example counts the instances of data in the LAST_NAME, DEPARTMENT, and JOBCODE fields in the EMPLOYEE data source.
TABLE FILE EMPLOYEE COUNT LAST_NAME AND DEPARTMENT AND JOBCODE END
The following shows the output of the request.
LAST_NAME DEPARTMENT JOBCODE COUNT COUNT COUNT --------- ---------- ------- 12 12 19
The EMPLOYEE data source contains data on 12 employees, with one instance for each LAST_NAME. While there are only two values for DEPARTMENT, there are 12 instances of the DEPARTMENT field because each employee works for one of the two departments. Similarly, there are 19 instances of the JOBCODE field because employees can have more than one job code during their employment.
WebFOCUS |