Using QMF

G. -- Grouping data

The keyword G. groups selected rows by a specified column for the purpose of performing operations on each group. G. accumulates the results by group, but it does not order the groups. (Use AO. or DO. to ensure the desired order.)

For example, you can group by department to determine each department's average salary with the following steps:

  1. Group the rows by department number (G. under DEPT).
  2. Specify one average for each department (_S under SALARY and AVG._S in an unnamed column to link _S to the SALARY column).
  3. Add P. in the columns you want the results selected.
  4. Add AO. to put them in ascending order by department.

When you run this query:



Q.STAFF | DEPT    | SALARY |          |
--------+---------+--------+----------|
        | G.P.AO. | _S     | P.AVG._S |

QMF produces this report:

  DEPT     AVG(SALARY)
------  ---------------
    10  20865.862500000
    15  15482.332500000
    20  16071.525000000
    38  15457.110000000
    42  14592.262500000
    51  17218.160000000
    66  17215.240000000
    84  16536.750000000

Generally, G. produces one group for each set of identical values in a column. If there are null values in the column, they form a single group.

Rules for G.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]