Exists
(Employee)
|
如果目前記錄中欄位 Employee 的值已經存在於任何先前讀取的記錄 (包含該欄位) 中,則會傳回 -1 (True)。
陳述式 Exists (Employee, Employee) 與 Exists (Employee) 相當。
|
Exists(Employee,
'Bill')
|
如果欄位值 'Bill' 被發現位於欄位 Employee 的目前內容中,則會傳回 -1 (True)。
|
Employees:
LOAD * inline [
Employee|ID|Salary
Bill|001|20000
John|002|30000
Steve|003|35000
] (delimiter is '|');
Citizens:
Load * inline [
Employee|Address
Bill|New York
Mary|London
Steve|Chicago
Lucy|Madrid
Lucy|Paris
John|Miami
] (delimiter is '|') where Exists (Employee);
Drop Tables Employees;
|
此結果位於表格中,您可以使用維度 Employee 和 Address 在表格視覺化中使用該表格。
where 子句:where Exists (Employee) 僅表示來自表格 Citizens 的名稱,這些名稱也位於載入至新表格的 Employees 中。Drop 陳述式會移除表格 Employees,以避免混淆。
結果
|
Employee |
Address |
Bill |
New York |
John |
Miami |
Steve |
Chicago |
|
|
Employees:
Load * inline [
Employee|ID|Salary
Bill|001|20000
John|002|30000
Steve|003|35000
] (delimiter is '|');
Citizens:
Load * inline [
Employee|Address
Bill|New York
Mary|London
Steve|Chicago
Lucy|Madrid
Lucy|Paris
John|Miami
] (delimiter is '|') where not Exists (Employee);
Drop Tables Employees;
|
where 子句包含 not: where not Exists (Employee, Name)。
這表示只有來自表格 Citizens 且不在 Employees 中的名稱才會被載入新表格中。
請注意,Citizens 表格中有兩個 Lucy 的值,但只有一個包含在結果表格中。載入第一列時,值會包含在 Employee 符號表格中。因此,檢查第二行時,值即已存在。
下一個範例顯示載入所有值的方式。
結果
|
Employee |
Address |
Mary |
London |
Lucy |
Madrid |
|
員工Load Employee As Name, ID, Salary; LOAD * inline [ Employee|ID|Salary Bill|001|20000 John|002|30000 Steve|003|35000 ] (delimiter is '|'); Citizens: Load * inline [ Employee|Address Bill|New York Mary|London Steve|Chicago Lucy|Madrid Lucy|Paris John|Miami ] (delimiter is '|') where not Exists (Name, Employee); Drop Tables Employees;
|
為了能夠取得 Lucy 的所有值,您需要變更兩件事:
-
將之前的載入新增至 Employees,您可在此將 Employee 重新命名為 Name。
載入員工作為名稱、ID、薪資;
-
將 Citizens 中的 Where 條件變更為:
not Exists (Name, Employee)。
這將會建立 Name 和 Employee 的其他符號表格。檢查 Lucy 的第二列時,這仍然不會存在於 Name。
Employee |
Address |
Mary |
London |
Lucy |
Madrid |
Lucy |
Paris |
|