Azure 數位 Twins 查詢語言參考: WHERE 子句Azure Digital Twins query language reference: WHERE clause

本檔包含 Azure 數位 Twins 查詢語言WHERE 子句 的參考資訊。This document contains reference information on the WHERE clause for the Azure Digital Twins query language.

WHERE 子句是查詢的最後一個部分。The WHERE clause is the last part of a query. 它是用來根據特定條件來篩選傳回的專案。It is used to filter the items that are returned based on specific conditions.

在查詢時,這個子句是選擇性的。This clause is optional while querying.

核心語法: WHERECore syntax: WHERE

WHERE 子句會與布林值條件一起使用,以篩選查詢結果。The WHERE clause is used along with a Boolean condition to filter query results.

條件可以是評估結果為布林值的 函數A condition can be a function that evaluates to a Boolean result. 您也可以使用 twins 和關聯性的屬性來建立自己的布林語句, (使用 .) 搭配比較或 contains 運算子來存取。You can also create your own Boolean statement using the properties of twins and relationships (accessed with .) with a comparison or contains-type operator.


具有屬性和運算子:With properties and operators:

--SELECT ...
--FROM ...
WHERE <twin-or-relationship-collection>.<property> <operator> <value-to-compare>

使用函式:With a function:

--SELECT ...
--FROM ...
WHERE <function-with-Boolean-result>


評估為值的條件 BooleanA condition evaluating to a Boolean value.


以下是使用屬性和運算子的範例。Here is an example using properties and operators. 下列查詢會在 WHERE 子句中指定,只傳回具有 $dtId Room1 值的對應項。The following query specifies in the WHERE clause to only return the twin with a $dtId value of Room1.

WHERE T.$dtId = 'Room1'

以下是使用函數的範例。Here is an example using a function. 下列查詢會使用 IS_OF_MODEL 函數,在 WHERE 子句中指定,以便只傳回具有模型的 twins dtmi:sample:Room;1The following query uses the IS_OF_MODEL function to specify in the WHERE clause to only return the twins with a model of dtmi:sample:Room;1. 如需函式的詳細資訊 IS_OF_MODEL ,請參閱 Azure 數位 Twins 查詢語言參考:函數For more about the IS_OF_MODEL function, see Azure Digital Twins query language reference: Functions.

WHERE IS_OF_MODEL('dtmi:sample:Room;1')