The following programs demonstrate the use of the AVERAGE function in a display statement. These programs: o Use a record selection expression to form a record stream from the view CURRENT_INFO, consisting of the records for which the value in the SALARY field is greater than 50000.00 o Calculate the average salary for these selected records o Print this average
1 – C Example
#include <stdio.h> DATABASE PERS = FILENAME "PERSONNEL"; double mean; main() { READY PERS; START_TRANSACTION READ_ONLY; GET mean = AVERAGE CI.SALARY OF CI IN CURRENT_INFO WITH CI.SALARY > 50000.00; END_GET; COMMIT; printf ("Average is: %f\n",mean); FINISH; }
2 – Pascal Example
program average_function (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; var mean : double; begin READY PERS; START_TRANSACTION READ_ONLY; GET mean = AVERAGE SH.SALARY_AMOUNT OF SH IN SALARY_HISTORY WITH SH.SALARY_AMOUNT > 50000.00; END_GET; COMMIT; writeln ('Average is: ', mean:10:2); FINISH; end.