Chapter 5 This chapter shows you how to tally the data in a group of records to find statistical information, such as the minimum or maximum value. You can answer questions like: What is the minimum salary for all the employees in a view? What is the average salary for all the employees in department 201? BASIS uses tables and statistical functions to calculate statistics for groups of records. In this chapter, you’ll learn how to: Create a table Calculate statistics for records using the statistical functions with tables Divide records into groups and calculate statistics for each group Supply a table with record data from joined views Rename a table column heading Reformat a table column Eliminate duplicate rows in a table 169 Creating a Table A table is a result set that contains actual data from records, not just pointers. This type of result set is also known as a value result set. Since tables contain actual data from records in a view, accessing the record information may take less processing time than accessing it through simple result sets containing pointers. Before discussing how to use tables to compute statistics for a group of records, we’ll first look at the table in its most basic form. The syntax for creating the most basic table is FIND table name , VALUES field or arithmetic expression field or arithmetic expression FROM WHERE view retrieval test Variable Component Definitions 170 table name the name for the table you create field the field from which the system gets data to form a column of the table arithmetic expression values combined together using arithmetic operators; for information about arithmetic operators, see “Components of Basic Searches.” view the view that contains the fields(s) from which the system gets data retrieval test a test that determines from which records in the view the system gets the data for the table Restrictions The name of the table can contain any printable character but can be no more than 32 characters long. The field cannot have the data type TEXT_STREAM. You cannot specify field lists for the field box. If you specify a compound field for the field box, you must specify a subfield number. A row in the table cannot be more than 250 characters long. You cannot update data retrieved in a table. Tables are supported by the FIND and TYPE commands only. Example 1 Suppose you want to create a table containing certain fields from all the records in the EMPLOYEE view. In your command, simply specify the names of the desired fields: table name fields view FIND TEMP VALUES ENO, NAME, DNO, JOB, SALARY FROM EMPLOYEE You can display the table by using the TYPE command. The system uses the field names as the default column headings. The table would look similar to the following: TYPE * ENO ----1001 1823 2312 2458 2843 10040 5235 2930 3395 3724 3912 NAME -------------DAVIS, JOE SMITH, JOHN MILLER, JOHN MARTIN, PETER JAMES, JOYCE KUNCHAL, KURT JOHNSON, JANE BLACK, THOMAS BROWN, SANDRA JACKSON, MARY LEMON, LINDA DNO --100 201 301 301 301 501 202 301 100 201 301 JOB -----------President Salesman Programmer Clerk Programmer Manager Secretary Manager Secretary Manager Programmer SALARY -------8,000.00 2,000.00 2,350.00 1,050.00 2,000.00 3,944.00 1,000.00 2,650.00 1,700.00 2,700.00 2,150.00 171 Example 2 Suppose you want to create a table containing the same fields as in example 1 but using the data from the records of employees in department 201 only. In this case, the command would look exactly like the one in the first example with the addition of a retrieval test like the following: FIND TEMP VALUES ENO, NAME, DNO, JOB, SALARY FROM EMPLOYEE + WHERE DNO = 201 The system finds all the records with the value 201 in the DNO field. Then it returns the data in the ENO, NAME, DNO, JOB, and SALARY fields in a table (i.e., value result set). The table would look similar to the following: TYPE * 172 ENO ----1823 3724 4801 5734 7408 6819 10002 NAME -------------SMITH, JOHN JACKSON, MARY JONES, PAUL ADAMS, PAULA JARVIS, JERRY DAY, THOMAS SCHMIDT, RANDY DNO --201 201 201 201 201 201 201 10012 10014 WRIGHT, EGOR PIZZINO, JUDY 201 201 JOB -----------Salesman Manager Salasman Clerk Salesman Salesman Administrative Assistant Clerk Administrative Assistant SALARY -------2,000.00 2,700.00 2,100.00 1,100.00 1,650.00 1,500.00 1,431.00 1,239.00 1,304.00 Calculating Statistics for Records When used in conjunction with statistical functions, tables compute statistics for records in a view. The statistical functions are the same as those discussed in “Components of Advanced Searches,” except their syntax is slightly different. In tables, statistical function expressions are made up of statistical functions attached to fields or arithmetic expressions, as shown below: statistical function expressions statistical function ( field ) or statistical function ( arithmetic expression ) Some examples of valid statistical function expressions are MAX(SALARY) AVG(SALARY+COMM) MIN(COMM) Values generated by statistical functions become the data contained in the columns of a table. The syntax for using statistical functions in a table is similar to the syntax for the most basic table in the previous section, except you specify statistical functions instead of fields. 173 The syntax for calculating statistics for records is: FIND table name VALUES statistical function expression , FROM statistical function expression view WHERE retrieval test See the variable component definitions and restrictions in the previous section where appropriate. Note: You can get similar information by using the TYPE command with the COUNT, MAX, MEAN, MIN, and TOTAL parameters; however, system performance is not as efficient as when you use tables and statistical functions. Example 1 Suppose you want to find the minimum, average, and maximum salaries for all the employees. In your FIND command, you specify the contents of your table by using statistical functions on the SALARY field. The command would look like the following: statistical function expressions table name view FIND TEMP VALUES MIN(SALARY), AVG(SALARY), MAX(SALARY) FROM EMPLOYEE A TYPE command displays the statistics: TYPE * F001 -----750.00 F002 ------1653.52 F003 ------8000.00 Note: If the data in the column is the product of a statistical function, the system uses the heading F00n, where n is the number of the column. You can change these headings by using an AS clause (explained later in this chapter). 174 Example 2 Suppose that you know the maximum salary of 8000 in the previous example belongs to the president of the company. If you want to find the maximum salary excluding the president’s, you could add a retrieval test to your FIND command like the following: FIND TEMP VALUES MAX(SALARY) FROM EMPLOYEE + WHERE JOB ^= 'PRESIDENT' The system examines the data from the SALARY field of all the records in the EMPLOYEE view except the record that contains the value PRESIDENT in its JOB field. From this data, it determines the maximum amount and returns this value in the table. Displaying the table shows that the maximum value is 3944.00: TYPE * F001 ------3944.00 Example 3 Suppose you want to find the maximum salary of all the salesmen, but you want to take into consideration any commission they might earn. To do this, you must use the MAX function on SALARY and COMM fields added together. You must also specify a retrieval test that obtains only the records whose JOB field contains the value SALESMAN. The FIND command would look like the following: FIND TEMP VALUES MAX(SALARY+COMM) FROM EMPLOYEE + WHERE JOB = 'SALESMAN' First the system forms a temporary simple result set holding all the records whose JOB field contains the value SALESMAN. Then the system adds the data in each record’s SALARY and COMM fields and determines which sum is the maximum value. This value is returned in the table. The TYPE command displays the table as shown below: TYPE * F001 ------3500.00 175 Expanded Capabilities of COUNT In the “Statistical Functions” section of “Components of Advanced Searches,” we saw how to use the COUNT function to count the number of non-null values in a field. When used with tables, the COUNT function has extra capabilities. These additional features and the corresponding syntax are described in the table below: To Use this syntax Eliminate records with duplicate values and count the remaining non-null values COUNT ( DISTINCT field ) Count the number of records COUNT ( * ) Some examples of valid commands using the COUNT function in the manner described above are: FIND TEMP VALUES COUNT(DISTINCT JOB) FROM EMPLOYEE FIND TEMP VALUES COUNT(DISTINCT JOB) FROM EMPLOYEE + WHERE SALARY > 200 FIND TEMP VALUES COUNT(*) FROM CLIENT Example 1 COUNT(DISTINCT) Suppose you want to find how many different jobs exist at the travel agency that owns the TOUR database. You could retrieve all the records in the EMPLOYEE view and display the values in the job fields. Then you could manually count the jobs, skipping those that are repeated on the list. Or, you could obtain this information by entering the following command: FIND TEMP VALUES COUNT (DISTINCT JOB) FROM EMPLOYEE 176 When creating the temporary result set, the system eliminates those records with a job that repeats a job already listed in the result set. Then it counts the remaining jobs in the set and returns a table consisting solely of the number it counted. Executing the TYPE command displays the following: F001 ---9 Example 2 COUNT(*) Suppose you want to find the average salary of all the employees and the number of records considered in the calculation. You could enter the following: FIND TEMP VALUES AVG (SALARY), COUNT(*) FROM EMPLOYEE The system creates a temporary result set containing the salaries of all the records. After calculating the average of these salaries and counting the number of records in the set, it returns these figures in a table. The display would be similar to the following: F001 ------1653.52 F002 ---131 Calculating Statistics for Multiple Groups of Records (GROUP BY Clause) In the last section, you learned how to tabulate statistics for a particular group of records, such as all the records in a view, all the salesmen’s records, and all the records of employees in department 201. But what if you want to find the maximum salary of employees in each department? Using the method in the other section, you would have to enter several FIND commands—one for each department number—like the following: FIND TEMP VALUES MAX(SALARY) FROM EMPLOYEE WHERE DNO = 101 FIND TEMP VALUES MAX(SALARY) FROM EMPLOYEE WHERE DNO = 201 FIND TEMP VALUES MAX(SALARY) FROM EMPLOYEE WHERE DNO = 202 The information you get from the above commands can be obtained in one table with one FIND command by using the GROUP BY clause. The GROUP BY clause assembles together records with the same value in the specified field and then calculates the specified statistics for each record group. 177 The syntax for calculating statistics for groups of records is FIND table name VALUES , column data column data FROM WHERE view GROUP BY retrieval test field , field Variable Component Definitions table name the name that you give to the table you want to create column data a field or statistical function expression from which the system gets data to form a column of the table view the view that contains the field(s) from which the system gets data for the table field the field according to which the system groups the data retrieval test a test that determines from which records the system gets the data for the table Restrictions 178 If you specify a field for one column data box and a statistical function for another column data box, you must also specify the field in the GROUP BY clause. You cannot specify field lists for the column data box or field box. If you specify a compound field, you must specify a subfield number. Example 1 For example, suppose you want to find the minimum and maximum salaries for each type of job in the EMPLOYEE view. You would need the following data to make up the columns of your table: job title, minimum salary, maximum salary. The FIND command would look like this: column data (field) column data (statistical function expressions) view table name field FIND TEMP VALUES JOB, MIN(SALARY), MAX(SALARY) FROM EMPLOYEE GROUP BY JOB First, the system groups all the records with the same job. Then it examines the data in the SALARY fields of the records in each job group to find the minimum and maximum salaries. The table would look like this: JOB -----------------------ADMINISTRATIVE ASSISTANT CLERK MANAGER OPERATOR PRESIDENT PROGRAMMER SALESMAN SECRETARY VICE-PRESIDENT F002 ------933.00 750.00 1300.00 902.00 8000.00 1354.00 1395.00 900.00 2629.00 F003 ------1446.00 1650.00 3944.00 1450.00 8000.00 2371.00 2100.00 1826.00 2902.00 Note: The system uses the name of the field for the column heading. If the data in the column is the product of a statistical function, the system uses the heading F00n, where n is the number of the column. You can change these headings by using the AS clause (explained later in the “Renaming Table Column Headings (AS Clause)” section). Example 2 You can also group records by more than one field. Suppose you wanted to see the minimum and maximum salaries for each job in each department. You could enter the following command: 179 FIND TEMP VALUES DNO, JOB, MIN(SALARY), MAX(SALARY) FROM + EMPLOYEE GROUP BY DNO, JOB The system first groups records whose DNO fields contain the same numbers. Then, within each department group, it groups records whose JOB fields contain the same values. Then it compares the data in the SALARY fields of the records in each job group within each department group to find the minimum and maximum salaries. The table would look similar to the following: DNO ---100 100 100 100 100 100 100 101 101 101 101 101 201 201 201 201 201 201 201 202 202 202 202 301 301 301 301 301 301 . . . 180 JOB ------------------------ADMINISTRATIVE ASSISTANT CLERK MANAGER OPERATOR PRESIDENT PROGRAMMER SECRETARY CLERK MANAGER SALESMAN SECRETARY VICE-PRESIDENT ADMINISTRATIVE ASSISTANT CLERK MANAGER OPERATOR PROGRAMMER SALESMAN SECRETARY MANAGER OPERATOR SALESMAN SECRETARY ADMINISTRATIVE ASSISTANT CLERK MANAGER PROGRAMMER SALESMAN SECRETARY F003 ---------1446.00 1500.00 2455.00 1015.00 8000.00 1790.00 1700.00 811.00 2500.00 395.00 1053.00 2629.00 1304.00 1100.00 2573.00 930.00 1364.00 1406.00 1186.00 1300.00 902.00 1643.00 900.00 993.00 867.00 2650.00 1354.00 1609.00 1034.00 F004 ---------1446.00 1650.00 2455.00 1015.00 8000.00 2194.00 1700.00 1200.00 2713.00 1395.00 1477.00 2629.00 1431.00 1239.00 2700.00 930.00 1793.00 2100.00 1612.00 2258.00 902.00 2015.00 1000.00 1213.00 1150.00 2791.00 2350.00 1627.00 1826.00 Example 3 Suppose you want to find the maximum and minimum salaries for each type of job in department 101. The FIND command would be the same as the one in example 2 with a retrieval test added to it. This retrieval test would restrict the records accessed from the EMPLOYEE view to only those with the value 101 in their DNO field. The FIND command would look like this: FIND TEMP VALUES DNO, JOB, MIN(SALARY), MAX(SALARY) FROM + EMPLOYEE WHERE DNO = 101 GROUP BY DNO, JOB The system retrieves the records whose DNO field contains 101. Then it arranges these records into groups according to the value in their JOB field. Within each job group of records, the system compares the values in the SALARY field to find the minimum and maximum values. The table would look similar to the following: DNO ---101 101 101 101 101 JOB ------------------------CLERK MANAGER SALESMAN SECRETARY VICE-PRESIDENT F003 ---------811.00 2500.00 395.00 1053.00 2629.00 F004 ---------1200.00 2713.00 1395.00 1477.00 2629.00 Note: Although the records accessed for the table all have the same department number, you must still group them by the DNO field (as well as the JOB field) because the DNO field is specified as one of the columns in the table. (See the restrictions at the beginning of this section.) If you didn’t want the DNO field to be part of the table, you could change the command to this: FIND TEMP VALUES JOB, MIN(SALARY), MAX(SALARY) FROM + EMPLOYEE WHERE DNO = 101 GROUP BY JOB Restricting Groups of Records (HAVING Clause) The HAVING clause operates the same as a WHERE clause except that it restricts groups of records instead of individual records. In other words, if the records in a view are divided into groups based on their department number, your table does not have to contain all the department groups. With the HAVING clause, you can limit the department groups based on some condition. Although the condition can be just about anything, the advantage of the HAVING clause is that the condition can test the value generated by a statistical function expression for each record group. For instance, you 181 can limit the department groups contained in the table to the ones that have an average salary greater than 1000. The condition in your HAVING clause would test the value generated by the statistical function expression AVG(SALARY) for each department group. Department groups for which the computed value is over 1000 will be part of the table. The syntax for restricting record groups is FIND , temp table column data VALUES WHERE column data FROM retrieval test view , field GROUP BY HAVING field retrieval test See the beginning of this section for definitions of the variable components used above. Restrictions/Guidelines Since the HAVING clause must compare some property of the group with a search value, there are restrictions on what retrieval test you may use with the HAVING clause: The field(s) you specify in the retrieval test must be the same field(s) you specified in the GROUP BY clause. For example: FIND TEMP VALUES DNO, MIN(SALARY) FROM EMPLOYEE + GROUP BY DNO HAVING DNO = 103:401 Instead of a field, you can specify a statistical function expression in the retrieval test. For example: FIND TEMP VALUES DNO FROM EMPLOYEE GROUP BY DNO HAVING + MIN(SALARY) > 900 The test operator you specify in the retrieval test must be a relational test operator. Example 1 An example can better convey the purpose of the HAVING clause. Suppose you want to list the departments that have a minimum salary greater than 900. You could enter FIND TEMP VALUES DNO FROM EMPLOYEE GROUP BY DNO HAVING + MIN(SALARY) > 900 182 The system first groups together records with the same values in their DNO field. Then it finds the minimum salary for each record group. If a record group’s minimum salary is greater than 900, the group’s department number (DNO) becomes an entry in the table. Displaying the table shows which departments satisfy the condition specified in the HAVING clause: TYPE * DNO --100 201 302 501 Example 2 Except for the restrictions already mentioned, all the other standard applications of retrieval tests apply for HAVING clauses. They can contain connector operators, arithmetic operators, or even nested WHERE clauses. For example, suppose you want to list the jobs that have a maximum salary greater than the minimum salary of managers. You could enter: FIND TEMP VALUES JOB, MAX(SALARY) FROM EMPLOYEE + GROUP BY JOB HAVING MAX(SALARY) > MIN(EMPLOYEE.SALARY + WHERE JOB = 'MANAGER') The system does the following tasks for the above FIND command: Groups records of employees that have the same job. Finds the maximum salary for each job group. Calculates the search value for the HAVING clause by performing the statistical function on a nested WHERE clause. (This search value is the minimum salary for managers.) Compares the maximum salaries of the job groups with the minimum salary of managers. The job groups that have a maximum salary greater than the minimum salary of managers will be part of the table. 183 The TYPE command displays the table: TYPE * JOB --VICE-PRESIDENT SECRETARY SALESMAN PROGRAMMER PRESIDENT MANAGER F002 ---2765.60 1363.26 1697.57 1935.84 8000.00 2586.60 Supplying a Table with Data from Records in Joined Views In all the previous sections, tables were built using data from records in a single view. However, you can also access data from records in joined views. The syntax for such a task is a combination of the syntax for a join operation and any of the syntax variations, described earlier, that create a table. The standard JOIN syntax (without the word FIND) is added to any of the tablegenerating syntaxes after the word FROM (where the name of the single view would normally go). The diagram below shows how the JOIN syntax fits into the GROUP BY clause syntax: 184 JOIN Syntax X FIND view 1 , view X , view 2 WHERE AND view X . view 1 fieldX . field1 join operator join operator view Y view 2 . fieldY . field2 , retrieval test GROUP BY Syntax FIND temp table VALUES , column data FROM GROUP BY field column data The definitions for the above variable components are the same as the ones in the standard JOIN and GROUP BY syntax. The same restrictions apply here too. Example 1 Suppose you want to create a basic table, but you want to fill it with values from records in joined views. The joined views are EMPLOYEE and DEPENDENT. The values you want for the table are from the fields NAME, ENO, and JOB in the EMPLOYEE view and NAME and RELATIONSHIP from the DEPENDENT view. As always, when working with joined views, you must be sure to qualify fields that have the same name in both views. The command would be as follows: FIND TEMP VALUES EMPLOYEE.NAME, EMPLOYEE.ENO, JOB, + DEPENDENT.NAME, DEPENDENT.RELATIONSHIP FROM EMPLOYEE, + DEPENDENT WHERE EMPLOYEE.ENO := DEPENDENT.ENO The system joins the views and then retrieves the data in the specified fields to make up the columns of the table. The table would look like this: 185 EMPLOYEE NAME --------------DAVIS, JOE DAVIS, JOE KUNCHAL, KURT KUNCHAL, KURT KUNCHAL, KURT JACKSON, MARY JONES, PAUL JONES, PAUL JONES, PAUL JONES, PAUL SMITH, NANCY SMITH, NANCY ADAMS, PAULA CRIST, RONALD CRIST, RONALD ACHILLES, HAROLD ACHILLES, HAROLD ACHILLES, HAROLD ACHILLES, HAROLD ELLIS, BOB ELLIS, BOB ELLIS, BOB ELLIS, BOB . . . ENO ----1001 1001 10040 10040 10040 3724 4801 4801 4801 4801 5519 5519 5734 10000 10000 10001 10001 10001 10001 10005 10005 10005 10005 JOB ---------PRESIDENT PRESIDENT MANAGER MANAGER MANAGER MANAGER SALESMAN SALESMAN SALESMAN SALESMAN MANAGER MANAGER CLERK CLERK CLERK MANAGER MANAGER MANAGER MANAGER PROGRAMMER PROGRAMMER PROGRAMMER PROGRAMMER DEPENDENT NAME ---------------DAVIS, MARY DAVIS, JAMES KUNCHAL, CANDICE KUNCHAL, DELIA KUNCHAL, IVAN JACKSON, GREG JONES, SALLY JONES, PAUL JONES, MARY JONES, KEN SMITH, HENRY BONN, STEVEN JAMES, LINDA CRIST, GAIL CRIST, DAVID ACHILLES, BETTY ACHILLES, OSCAR ACHILLES, LYNN ACHILLES, IDA ELLIS, TEERI ELLIS, PHIL ELLIS, RUSS ELLIS, SUSAN RELATION -------WIFE CHILD WIFE CHILD CHILD CHILD WIFE CHILD CHILD CHILD HUSBAND OTHER MOTHER WIFE CHILD WIFE CHILD CHILD CHILD WIFE CHILD CHILD CHILD Example 2 Suppose you want to find the average salary of employees in each building. Since salary information is in the EMPLOYEE view and building information is in the DEPARTMENT view, you must join these two views before grouping their records by building. The FIND command would look like this: FIND TEMP VALUES BUILDING_NO, AVG(SALARY) FROM EMPLOYEE, + DEPARTMENT WHERE EMPLOYEE.DNO := DEPARTMENT.DNO + GROUP BY BUILDING_NO After the system joins the views EMPLOYEE and BUILDING, it groups records with the same building numbers. Then it calculates the average salary for each building group. The result set display would look similar to the following: 186 TYPE * BUILDING_NO ----------1 2 3 4 6 7 8 9 F002 ---2416.66 1683.50 1519.69 1232.07 1353.60 1625.05 1678.00 1772.60 Renaming Table Column Headings (AS Clause) By default, the system uses the field name specified in the FIND command as the column heading when a table is displayed. If the data in the column is the product of a statistical function, the system uses the heading F00n ,where n is the number of the column. The system also uses the default F00n heading when the source of the table data is records from joined views and the field you specify has the same name in both views. You can change these default column headings by using the AS clause. The AS clause goes after each field or statistical function expression with a column heading you want to change. These fields or statistical function expressions can be part of any of the FIND syntax variations, shown in the previous sections, that create a table. The syntax for renaming a column heading is AS column name Restrictions/Guidelines The column name may contain any printable character except break characters. There is no restriction on the length of column names. (If your column name wraps to the next line, increase the column width through the TYPE command. For more information about the TYPE command, see Interactive FQM Commands. Example In a previous example, you found the maximum and minimum salaries of each type of job in the EMPLOYEE view: FIND TEMP VALUES JOB, MIN(SALARY), MAX(SALARY) + FROM EMPLOYEE GROUP BY JOB 187 The column headings were JOB, F001, and F002. To change these headings to more descriptive names, you could enter the following: column heading column heading FIND TEMP VALUES JOB AS JOB_TITLE, MIN(SALARY) AS MIN_SALARY, + MAX(SALARY) AS MAX_SALARY FROM EMPLOYEE GROUP BY JOB column heading When you display the table, you will see your new headings: JOB_TITLE -----------------------ADMINISTRATIVE ASSISTANT CLERK MANAGER OPERATOR PRESIDENT PROGRAMMER SALESMAN SECRETARY VICE-PRESIDENT MIN_SALARY ---------933.00 750.00 1300.00 902.00 8000.00 1354.00 1395.00 900.00 2629.00 MAX_SALARY ---------1446.00 1650.00 3944.00 1450.00 8000.00 2371.00 2100.00 1826.00 2902.00 Formatting a Table Column (Data Types) When you create a table, the system formats each column according to the data type of the corresponding fields. These data types were specified by your DBA when the database was set up. If the values in a table column are generated by a calculation (for example, AVG(SALARY) or SALARY+500), the system often selects a data type called approximate numeric for these values. Since the default data types may not give the columns in your table the format you desire, BASIS gives you the option of changing the data type for the values in any of your table columns. The syntax for changing the data type goes after each field, arithmetic expression, or statistical function expression that makes up the column data. If you also specify an AS clause, the syntax for changing a data type goes before it. The syntax for changing a data type is 188 data type symbol : . precision scale See the table below for a list of the data types and their corresponding symbols, precisions, and scales. An automatic precision means that you do not have to specify a precision because the system automatically defaults to a precision based on your host machine. Data Type Symbol Precision (or Size) Exact Binary E 1 to 31 Integer I automatic Exact Decimal P 1 to 31 Approximate Numeric A 1 to 28 Real R automatic Double D automatic Complex Numeric X 1 to 14 Logical L automatic Character C 1 to 250 Scale 0 to 31 For a detailed explanation of each data type, see Database Definition and Development, “Fields.” 189 Some sample FIND commands that change the data type of a table column are FIND TEMP VALUES AVG(SALARY):P10.2 FROM EMPLOYEE FIND TEMP VALUES SALARY+500:P10.2 AS SAL_AND_BONUS FROM + EMPLOYEE FIND TEMP VALUES ZIP:I FROM CLIENT Example In a previous example you found the maximum earnings of salesmen by adding their salary and commission together: FIND TEMP VALUES MAX(SALARY+COMM) FROM EMPLOYEE + WHERE JOB = 'SALESMAN' For the sake of simplicity, that example’s display showed the column values in exact decimal format. However, in actuality, if you entered the above FIND command and displayed the table, the system would present the column values in scientific notation, as shown below: TYPE * F001 -----------------------------------0.3500000000000000000000000000E+0004 To change the data type format to exact decimal with a precision of 10 and a scale of 2, you could enter the following FIND command: data type symbol precision scale FIND TEMP VALUES MAX(SALARY+COMM):P10.2 FROM EMPLOYEE WHERE + JOB = 'SALESMAN' The display for this table would look similar to the following: TYPE * F001 ------3500.00 190 Eliminating Duplicate Rows in Tables (DISTINCT) Typically, when the system creates a table, each piece of specified information from the view makes up one row of the table. At times, one row will contain the same information as another row. For instance, if you create a table that contains only the values from the DNO field of records in the EMPLOYEE view, many rows will have the same department number. To eliminate this type of duplication, you can use the DISTINCT modifier. The DISTINCT modifier can be entered in any of the FIND syntax variations for creating a table shown in the previous sections of this chapter. Place the DISTINCT modifier right after the word FIND and before the table name. Note: If you don’t specify the DISTINCT modifier in your FIND command, the system defaults to the ALL modifier, which supplies as many rows for a table as needed to accommodate all the specified information from the view. Example Suppose you want to find out all the possible jobs one can have at the travel agency that owns the TOUR database. You could retrieve all the records and display the values in their JOB fields. However, since many employees have the same job, there would be many jobs repeated in the display. You would have to check manually through the display to narrow the jobs down to the basic occupations. You can obtain the same information by executing the following FIND command: FIND DISTINCT TEMP VALUES JOB FROM EMPLOYEE The system creates a table containing the data from the JOB field of records in the EMPLOYEE view and eliminates any duplicate rows. Executing the TYPE command displays the following: JOB -----------------------ADMINISTRATIVE ASSISTANT CLERK MANAGER OPERATOR PRESIDENT PROGRAMMER SALESMAN SECRETARY VICE-PRESIDENT 191 192
© Copyright 2026 Paperzz