Using QMF

Sorting the rows in a query

After you select the rows to display on your report, you can specify the way you want to sort the rows on the report. In this example, you will see how to sort the rows in ascending order by department number.

To sort rows:

  1. On the Specify panel, select choice 4, Sort. The Sort panel displays with choice 1, Ascending already selected for you.

    Figure 35. The Sort panel

    +--------------------------------------------------------------------------------+
    | PROMPTED QUERY      USERID.MYQUERY                  MODIFIED  LINE             |
    |                                      +--------------------------------------+  |
    |   Tables:                            |                 Sort                 |  |
    |     Q.STAFF                          |                                      |  |
    |                                      | Select the order for sorting and the |  |
    |   Columns:                           | column you want to sort.             |  |
    |     NAME                             |                                      |  |
    |     DEPT                             | Order...                             |  |
    |     SALARY                           | 1 1. Ascending (A-Z, 0-9)            |  |
    |     COMM                             |   2. Descending (9-0, Z-A)           |  |
    |     SALARY+COMM                      |                          1 to 5 of 5 |  |
    |                                      | Columns...                           |  |
    |   Row Conditions:                    |   1. SALARY+COMM                     |  |
    |     If COMM Is Not NULL              |   2. NAME                            |  |
    |     And SALARY+COMM Is Greater Than  |   3. DEPT                            |  |
    |                                      |   4. SALARY                          |  |
    |   Sort:                              |   5. COMM                            |  |
    |   > ...                              +--------------------------------------+  |
    |                                      | F1=Help  F7=Backward  F8=Forward     |  |
    |                                      +--------------------------------------+  |
    +--------------------------------------------------------------------------------+
  2. Leave 1 selected if you want to sort the rows in ascending order, or type 2 to sort the rows in descending order.

  3. Type the number of the column that contains the data you want to sort.
  4. Press Enter.

The sort order you specified is displayed in the echo area, and the Specify panel displays.

Repeat these steps if you want to sort on other columns. For example, in this query, in addition to sorting by department number, you might also want to sort by name within department.

QMF displays the sort order you selected, as shown in Figure 36.

Figure 36. QMF displays the order in which rows will be sorted.

+--------------------------------------------------------------------------------+
| PROMPTED QUERY                           MODIFIED     LINE     1               |
|                                                                                |
|   Tables:                                                                      |
|  _     Q.STAFF                                                                 |
|                                                                                |
|   Columns:                                                                     |
|  _     NAME                                                                    |
|  _     DEPT                                                                    |
|  _     SALARY                                                                  |
|  _     COMM                                                                    |
|  _     SALARY+COMM                                                             |
|                                                                                |
|   Row Conditions:                                                              |
|  _     If COMM Is Not NULL                                                     |
|  _     And SALARY+COMM Is Greater Than 17000                                   |
|                                                                                |
|   Sort:                                                                        |
|  _     Ascending by DEPT                                                       |
|  _     Ascending by NAME                                                       |
|                                                                                |
| 1=Help       2=Run        3=End      4=Show SQL  5=Change        6=Specify     |
| 7=Backward   8=Forward    9=Form     10=Insert   11=Delete       12=Report     |
| OK, CANCEL command executed successfully.                                      |
| COMMAND ===>                                     SCROLL ===> PAGE              |
+--------------------------------------------------------------------------------+

QMF displays the report in Figure 37 when you run this query. The rows are first sorted by department number, and then by employee name within each department.

Figure 37. The report is sorted by department number and employee name.

+--------------------------------------------------------------------------------+
|   NAME         DEPT      SALARY        COMM  EXPRESSION 1                      |
|   ---------  ------  ----------  ----------  ------------                      |
|   ROTHMAN        15    16502.83     1152.00      17654.83                      |
|   PERNAL         20    18171.25      612.45      18783.70                      |
|   O'BRIEN        38    18006.00      846.55      18852.55                      |
|   QUIGLEY        38    16808.30      650.25      17458.55                      |
|   KOONITZ        42    18001.75     1386.70      19388.45                      |
|   SMITH          51    17654.50      992.80      18647.30                      |
|   WILLIAMS       51    19456.50      637.65      20094.15                      |
|   GONZALES       66    16858.20      844.00      17702.20                      |
|   GRAHAM         66    21000.00      200.30      21200.30                      |
|   WILSON         66    18674.50      811.50      19486.00                      |
|   EDWARDS        84    17844.00     1285.00      19129.00                      |
+--------------------------------------------------------------------------------+


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