Exists - 指令碼函數
Exists() 會判定特定欄位值是否已載入資料載入指令碼的欄位中。該函數會傳回 TRUE 或 FALSE﹐因此可以在 LOAD 陳述式或 IF 陳述式的 where 子句中使用。
Syntax:
Exists(field_name [, expr])
Return data type: 布林
Arguments:
引數 | 描述 |
---|---|
field_name |
想要搜尋值的欄位名稱。您可以使用不含引號的明確欄位名稱, 欄位必須已由指令碼載入。這代表,您無法參考在指令碼中進一步向下的子句中載入的欄位。 |
expr |
您想要檢查是否存在的值。您可以使用明確的值或參考目前 LOAD 陳述式中一個或數個欄位的運算式。 資訊備註您無法參考未納入目前 LOAD 陳述式的欄位。
此引數為選擇性。若您省略,函數將會檢查目前記錄中 field_name 的值是否已存在。 |
範例中使用的資料:
Example:
Exists (Employee)
如果目前記錄中欄位 Employee 的值已經存在於任何先前讀取的記錄 (包含該欄位) 中,則會傳回 -1 (True)。
陳述式 Exists (Employee, Employee) 與 Exists (Employee) 相當。
Example:
Exists(Employee, 'Bill')
如果欄位值 'Bill' 被發現位於欄位 Employee 的目前內容中,則會傳回 -1 (True)。
Example:
此結果位於表格中,您可以使用維度 Employee 和 Address 在表格視覺化中使用該表格。
where 子句:where Exists (Employee) 僅表示來自表格 Citizens 的名稱,這些名稱也位於載入至新表格的 Employees 中。Drop 陳述式會移除表格 Employees,以避免混淆。
Employee | Address |
Bill | New York |
John | Miami |
Steve | Chicago |
Example:
where 子句包含 not: where not Exists (Employee, Name)。
這表示只有來自表格 Citizens 且不在 Employees 中的名稱才會被載入新表格中。
請注意,Citizens 表格中有兩個 Lucy 的值,但只有一個包含在結果表格中。載入第一列時,值會包含在 Employee 符號表格中。因此,檢查第二行時,值即已存在。
下一個範例顯示載入所有值的方式。
員工 | 地址 |
---|---|
Mary | London |
Lucy | Madrid |
Example:
為了能夠取得 Lucy 的所有值,您需要變更兩件事:
-
將之前的載入新增至 Employees,您可在此將 Employee 重新命名為 Name。
載入員工作為名稱、ID、薪資;
-
將 Citizens 中的 Where 條件變更為:
not Exists (Name, Employee)。
這將會建立 Name 和 Employee 的其他符號表格。檢查 Lucy 的第二列時,這仍然不會存在於 Name。
員工 | 地址 |
---|---|
Mary | London |
Lucy | Madrid |
Lucy | Paris |