Here’s how to use diff() function.
Description:
Calculate the difference between sequence members of a sequence by removing from the first sub-sequence the members that exist in any of the other sub-sequences.
Syntax:
A .diff()
Note:
Generally sequence A contains multiple sub-sequences. The function calculates the difference between its sequence-type members to ensure that the new sequence doesn’t include any member of the other sub-sequences.
The algorithm is to compute the difference between the first sub-sequence and the second one, then compute the difference between the result and the third sub-sequence, and so on and so forth.
If the sub-sequences are record sequences, compare records in same position through their store addresses. If the addresses are different, the records are different members.
Parameters:
A |
A sequence whose members are sequences |
Return value:
A new sequence created by performing difference operations on A’s first sub-sequence and the other sub-sequences.
Example:
|
A |
|
1 |
=[[1,2,3,4,5],[3,7,8]].diff() |
[1,2,4,5] |
2 |
=[[1,2,3],[3,2],[1]].diff() |
[] |
3 |
=[[1,2,2,3],[2]].diff() |
[1,2,3] remove only one of the duplicate members |
4 |
=demo.query("select top 2 * from EMPLOYEE") |
|
5 |
=demo.query("select top 1 * from EMPLOYEE") |
|
6 |
=[A4,A5].diff() |
Since A4 and A5 come from different table sequences and have different store addresses, so the same records are regarded as different members |
Related functions:
Description:
Calculate difference between the sequence-type members in a specified sequence to generate a new sequence where the first subsequence won’t contain members that exist in the other sub-sequences.
Syntax:
A.diff(x)
Note:
Generally sequence A contains multiple sub-sequences. The function loops through each sub-sequence of A to compute expression x and get the difference between these sub-sequences, ensuring that the difference result doesn’t include any member of the other sub-sequences.
The algorithm is to compute the difference between the first sub-sequence and the second one, then compute the difference between the result and the third sub-sequence, and so on and so forth.
Parameters:
A |
A sequence whose members are sequences |
x |
An expression that returns a sequence |
Return value:
A sequence
Example:
|
A |
|
1 |
=demo.query("select * from EMPLOYEE where GENDER = 'M' order by NAME") |
|
2 |
=demo.query("select * from EMPLOYEE where GENDER = 'F' order by NAME") |
|
3 |
=[A1,A2].diff(~.(NAME)) |
Remove only one of the duplicate members |
Related functions: