Description:
Collect the results to the master cell after iterating over and processing an ordered cursor by group.
Syntax:
forr cs;x
Note:
Iterate over the ordered cursor cs, grouped by field x. In each iteration, the value of the last calculation cell is automatically collected to form a cursor, which is assigned to the cell containing forr. In subsequent calculations, the forr master cell itself will be used directly as a cursor.
Parameter:
|
cs |
An ordered cursor. |
|
x |
The grouping field. |
Return value:
Cursor
Example:
|
|
A |
B |
|
|
1 |
=demo.cursor("select EID,NAME,DEPT,BIRTHDAY,SALARY from EMPLOYEE order by DEPT") |
|
Return an ordered cursor. |
|
2 |
forr A1;DEPT |
|
Group and traverse data by department. |
|
3 |
|
=A2.sum(SALARY) |
Calculate the sum of salaries of the employees in the department. |
|
4 |
|
=A2.avg(age(BIRTHDAY)) |
Calculate the average age in the department. |
|
5 |
|
=new(B3:totalSalary,B4:avgAge, A2.count():countPerson) |
Construct a summary record with three fields: use the value of B3 for the totalSalary column, the value of B4 for the avgAge column, and the number of people in the current group for the countPerson column. Finally, collect the result in cell A2. |
|
6 |
=A2.fetch() |
|
Fetch data from A2’s cursor:
|
