cs.g roup()

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

Description:

Attach the action of grouping records by comparing only adjacent records to the cursor and return the original cursor.

Syntax:

cs.group(x,…)

Note:

The function attaches a computation to cursor cs, which groups cursor cs by expression x, whose value is compared only with the adjacent records, and returns the original cursor. Cursor cs should be ordered. The operation is equal to a merge and supports multicursors.

This is a delayed function.

Option:

@i

x is a Boolean 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 to the original cursor; here it is number 1 instead of letter l

@v

When parameter cs is a cursor based on pure table sequence, copy each grouped subset as a new pure table sequence

Parameter:

cs

A cursor or multicursor

x

Grouping expression

Return value:

Cursor

Example:

 

A

 

1

=demo.cursor("select * from EMPLOYEE").sortx(GENDER,DEPT)

Return a cursor where data is ordered by GENDER and DEPT.

2

=A1.group(GENDER,DEPT)

Attach a computation to cursor A1, which puts records in the same group when two neighboring records have same GENDER and DEPT values, and return the original cursor.

3

=A1.fetch()

Fetch data from cursor A1 where A2’s computation is executed (fetch data in batches when there is a huge amount of data):

When @i option is present:

 

A

 

1

=demo.cursor("select * from STOCKRECORDS where STOCKID='000062' ").sortx(DATE)

Return a cursor where data is ordered by DATE.

2

=A1.group@i(CLOSING<CLOSING[-1])

Attach a computation to cursor A1, which, with @i option, creates a new group whenever CLOSING value in the current record is less than that in the previous record, and return the original cursor.

3

=A1.fetch()

Fetch data from cursor A1 where A2’s computation is executed:

When @1 option is present:

 

A

 

1

=demo.cursor("select EID,NAME,DEPT,HIREDATE from EMPLOYEE").sortx(DEPT,HIREDATE)

Return a cursor where data is ordered by DEPT and HIREDATE.

2

=A1.group@1 (DEPT)

Attach a computation to cursor A1, which, with @1 option, groups records in the cursor by DEPT and gets the first record in each group, and return the original cursor.

3

=A1.fetch()

Fetch data from cursor A1 where A2’s computation is executed:

When parameter cs is a cursor based on pure table sequence:

 

A

 

1

=demo.cursor@v("select * from EMPLOYEE order by GENDER,DEPT")

Return a cursor of pure table sequence.

2

=A1.group@v(GENDER,DEPT)

Attach a computation to cursor A1, which, with @v option, copies each grouped subset as a new pure table sequence, and return the original cursor.

3

=A1.fetch()

Get the number of groups in cursor A1 where A2’s computation is executed.

Related function:

A.group(xi,…)

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