ch.gr oupx()

Read(1079) Label: channel, ordered records, group,

Description:

Group records in a channel and return a channel.

Syntax:

ch.groupx(x:F,…;y:G…)

Note:

The function groups records in channel ch according to grouping expression xto get a channel having F,...G,… fields. The result table sequence in the channel is ordered by x.Values of G field are the results of computing expression y, which is an aggregate function executed on ch, over each group. It aims to fetch the grouping result set from the channel. 

Option:

@n

With the option the value of expression x is a group number, which points to the desired group

Parameter:

ch

Channel

x

Grouping expression

F

Field name in the resulting table sequence

y

An aggregate function on channel ch, which only supports sum/count/max/min/top /avg/iterate; the parameter Gi should be given up if function iterate(x,a;Gi,…) is used

G

The aggregate fields in the resulting table sequence

Return value:

Channel

Example:

 

A

 

1

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

 

2

=channel()

Create a channel.

3

=channel()

Create a channel.

4

=A1.push(A2,A3)

Be ready to push the data in A1’s cursor into A2’s channel and A3’s channel, but the action needs to wait.

5

=A2.groupx(DEPT:dept;sum(SALARY):TotalSalary)

Group and sort records by DEPT field.

6

=A3.groupx@n(if(GENDER=="F",1,2):SubGroups;sum(SALARY):TotalSalary)

The value of expression x is a group number; put records where GENDER is “F” into the first group and others into the second group, and then aggregate each group.

7

=A1.select(month(BIRTHDAY)==2)

 

8

=A1.fetch()

Attach a fetch operation to A7’s cursor.

9

=A2.result()

Return the result as a cursor.

10

=A3.result()

Return the result as a cursor.