関数集約関数Combinator examplesanyIfanyIf 説明 Ifコンビネータは、指定された条件に一致する、特定のカラムから最初に遭遇した要素を選択するためにany集約関数に適用できます。 使用例 この例では、成功フラグを持つ販売データを格納するテーブルを作成し、anyIfを使用して200を超えたおよび未満の最初のtransaction_idを選択します。 まず、テーブルを作成し、データを挿入します: CREATE TABLE sales( transaction_id UInt32, amount Decimal(10,2), is_successful UInt8 ) ENGINE = MergeTree() ORDER BY tuple(); INSERT INTO sales VALUES (1, 100.00, 1), (2, 150.00, 1), (3, 155.00, 0), (4, 300.00, 1), (5, 250.50, 0), (6, 175.25, 1); SELECT anyIf(transaction_id, amount < 200) AS tid_lt_200, anyIf(transaction_id, amount > 200) AS tid_gt_200 FROM sales; ┌─tid_lt_200─┬─tid_gt_200─┐ │ 1 │ 4 │ └────────────┴────────────┘ 関連項目 any Ifコンビネータ