P.align(n,y)

Read(419) Label: sequence, align,

Description:

Perform alignment grouping on a record sequence.

Syntax:

P.align(n,y)

Note:

The function divides record sequence P into n groups according to grouping expression y and alignment succeeds if the result of y equals to the corresponding group number. The function is equivalent to P.align(to(n),y).

Parameter:

P

A record sequence

n

An integer, which is the number of groups

y

An expression whose result is an integer

Option:

@a

Return all members for each group, where members form a sequence; the function by default returns only the first eligible member for each group

@r

With this option, parameter y is an integer sequence

@p

Return values that are sequence numbers of members of P

Return value:

Sequence

Example:  

When parameter y is an integer:

 

A

 

1

=demo.query("select * from FAMILY")

2

=A1.align(11,EID)

Divide A1’s record sequence into 11 groups according to EID values, which correspond to group numbers one by one, and return the first eligible member for each group.

3

=A1.align@a(11,EID)

Divide A1’s record sequence into 11 groups according to EID values, which correspond to group numbers one by one, and, as @a is present, return all eligible members for each group.

4

=A1.align@ap(11,EID)

As @p is present, return values that are sequence numbers of EID values in A1.

When parameter y is an integer sequence:

 

A

 

1

=demo.query("select EID,NAME,DEPT  from EMPLOYEE")

2

=demo.query("select  *  from DEPARTMENT")

3

=A1.derive(A2.pselect@a(DEPT==A1.DEPT): DeptNo)

Find sequence numbers of DEPARTMENT records corresponding to EMPLOYEE table and then form them into an integer sequence and store it in DeptNo field.

4

=A3.align@r(8,DeptNo)

Align records directly to group number according to DeptNo field.

5

=A3.align@rp(8,DeptNo)

As @p option is present, return sequence numbers of records.