Calculates a value based on a value expression for every record in a record stream. When you use a statistical expression (except for COUNT), you specify a value expression and a record selection expression (RSE). Oracle Rdb first evaluates the value expression for each record in the record stream formed by the RSE. Then it calculates a single value based on all the results of the first step. Statistical expressions are also called aggregate expressions. For more information on value expressions and record selection expressions, ask for HELP on Value_expr and RSE.
1 – Format
(B)0[mstatistical-expr = qqqqqqqwqq> [4mMAX[m qqqqqwqq> value-expr qqwqq> [4mOF[m qq> rse qq> tqq> [4mMIN[m qqqqqu x tqq> [4mTOTAL[m qqqu x tqq> [4mAVERAGE[m qj x mqq> [4mCOUNT[m qqqqqqqqqqqqqqqqqqqqqj
1.1 – MAX
--> MAX --> value-expr --> OF --> rse --> Find the highest paid employee in the company: START_TRANSACTION READ_ONLY FOR SAL IN CURRENT_SALARY WITH SAL.SALARY_AMOUNT = MAX CURR.SALARY_AMOUNT OF CURR IN CURRENT_SALARY PRINT SAL.EMPLOYEE_ID, SAL.LAST_NAME, SAL.SALARY_AMOUNT END_FOR COMMIT
1.2 – MIN
--> MIN --> value-expr --> OF --> rse --> Find the job title with the smallest minimum salary: FOR J IN JOBS WITH J.MINIMUM_SALARY = MIN JM.MINIMUM_SALARY OF JM IN JOBS PRINT J.JOB_TITLE, J.MINIMUM_SALARY END_FOR
1.3 – TOTAL
--> TOTAL --> value-expr --> OF --> rse --> Assign the total payroll for the company to a host language variable: &RDB& START_TRANSACTION READ_ONLY &RDB& GET TOTAL-SALARY = TOTAL CH.SALARY_AMOUNT &RDB& OF CH IN CURRENT_SALARY &RDB& END_GET &RDB& COMMIT
1.4 – AVERAGE
--> AVERAGE --> value-expr --> OF --> rse --> Display the average salary of all the employees whose salaries exceed $50,000: PRINT AVERAGE CS.SALARY_AMOUNT OF CS IN CURRENT_SALARY WITH CS.SALARY_AMOUNT GT 50000
1.5 – COUNT
--> COUNT --> OF --> rse --> The following COBOL code fragment finds out the number of employees who live in a particular state, specified by the host language variable STATE: ACCEPT STATE. &RDB& GET STATE-COUNT = COUNT OF E IN EMPLOYEES &RDB& WITH E.STATE = STATE &RDB& END_GET DISPLAY "Number of employees in ", STATE, " is ", STATE-COUNT.
2 – More
If you invoke multiple databases in the RDO interface and declare an aggregate expression, Oracle Rdb returns an %RDB-E-INVALID_BLR error. For example: RDO> INVOKE DATABASE FEE = FILENAME USER1:[STUDENT_FEES]STUDENTDB RDO> INVOKE DATABASE STA = FILENAME USER2:[STUDENT_FEES]STATS RDO> RDO> START_TRANSACTION ON FEE USING cont> (READ_ONLY RESERVING FEE.TRANS FOR SHARED READ) AND cont> ON STA USING (READ_WRITE RESERVING STA.STATDATA FOR cont> EXCLUSIVE WRITE) RDO> RDO> FOR TX IN FEE.TRANS SORTED BY TX.SNO, TX.SESS, TX.TYPE cont> REDUCED TO TX.SNO, TX.SESS, TX.TYPE cont> WITH TX.SESS = "91S" cont> STORE SX IN STA.STATDATA USING cont> SX.SNO = TX.SNO; cont> SX.SESS = TX.SESS; cont> SX.TYPE = TX.TYPE; cont> SX.AMOUNT = (TOTAL T1.AMOUNT OF T1 IN FEE.TRANS WITH cont> T1.SNO = TX.SNO AND cont> T1.SESS = TX.SESS AND cont> T1.TYPE = TX.TYPE); cont> END_STORE cont> END_FOR %RDB-E-INVALID_BLR, request BLR is incorrect at offset 172 RDO> ROLLBACK;