cs .group()

Read(477) Label: cursor records, group, adjacent,

Description:

Group cursor records by comparing only adjacent records and return the original cursor.

Syntax:

cs.group(x,…)

Note:

The function groups cursor cs containing a set of records by expression x, according to which only the adjacent records are compared, and return the original cursor of sequences. Cursor cs should be ordered. The operation is equal to a merge and supports multicursors.

Options:

@i

x is a bool expression. Begin a new group when a record makes it return true. In this case there should be only one x.

@1

Get the first record of every group to form a record sequence and return it; here it is number 1, instead of letter l

@q(x:F,…;x’:F’,…;…)

When the cursor is ordered by the first grouping field, just sort the grouped data by the following field(s); support memory grouping

@s

Sort only without grouping; must work with @q option

Parameters:

cs

A cursor containing a set of records

x

Grouping expression; multiple fields/expressions for grouping will be separated from each other with the comma.

Return value:

The orginal cursor

Example:

 

A

 

1

=demo.cursor("select * from EMPLOYEE")

 

2

=A1.group(GENDER,DEPT)

Put adjacent records whose GENDER and DEPT values are equal into same group, and return the original cursor

3

=demo.cursor("select * from EMPLOYEE")

 

4

=A3.group@i(GENDER=="F").fetch()

Begin a new group as long as the record satisfies GENDER=="F"

5

=demo.cursor("select * from EMPLOYEE order by GENDER  ")

 

6

=A5.group@1(GENDER).fetch()

Return the first record of each group

7

=demo.cursor("select * from EMPLOYEE order by DEPT ")

Retrieve data of EMPLOYEE table, sort it by DEPT and return data as a cursor

8

=A7.group@q(DEPT;GENDER)

A7’s cursor is already ordered by DEPT, so the data just need to be ordred by group by GENDER

9

=A7.group@qs(DEPT:DEPT;GENDER:GENDER).fetch()

Sorted only without grouping

Related functions:

A.group(xi,…)

A.group(x:F,…;y:G,…)