SQL Condition
Detects rows for which a SQL condition of your own is true.
The SQL Condition monitor finds the rows for which a SQL condition you write is true, and alerts you when there are too many.
When to Use
- SQL functions in the rule: The rule needs functions that the No-Code Condition editor does not offer, such as date differences:
DATEDIFF(day, my_start_date, my_end_date) > 7. - Arithmetic across fields or tables: Join two tables, and find rows whose amount is greater than the total of the related row in the other table.
Compared with the SQL Query monitor, you only write the condition: Sifflet handles incremental scans, the where clause, group by, and joins.
How It Works
For each data point, Sifflet counts the rows for which the condition is true, and computes:
- Count (default value mode): The number of matching rows.
- Percentage: The share of matching rows among the rows checked for the data point, in percent. These are the rows of the period in incremental scan mode (for example, all the rows created that day), or all the rows of the table in full dataset scan mode. Rows excluded by the where clause are not counted.
The default static threshold fails when the data point is greater than 0, that is, as soon as one row matches.
Example
You want at least 95% of the orders to ship within 7 days. Create a SQL Condition monitor on orders with the following settings (here on Snowflake):
- SQL condition:
DATEDIFF(day, created_at, shipped_at) > 7, with the fields inserted from the autocompletion list. - Monitoring mode: Incremental scan, with
created_atas the time window column and a daily time-based data aggregation. - Value mode: Percentage.
- Threshold: Static, Greater than
5.
Usually, about 2% of the orders of a day ship after more than 7 days. For the orders of June 17, a strike at the warehouse delays shipping, and 12% of the orders ship after more than 7 days. The data point of June 17 is 12%, greater than 5%, so the monitor fails.
Configure the Monitor
SQL Condition Settings
Datasets and joins: Select the dataset to monitor and, optionally, join a second dataset, as for the No-Code Condition monitor.
SQL condition: A boolean SQL expression, evaluated for each row. Rows for which it is true are counted as failing. Do not include SELECT or FROM.
In the condition, fields use a special format, datasetId:fieldName. In the UI, start typing the name of a table or field, and select the field in the autocompletion list to insert it in this format. For example, with my_table (datasetId1) joined to my_other_table (datasetId2):
DATEDIFF(day, datasetId1:my_start_date, datasetId1:my_end_date) > 7
datasetId2:my_amount > datasetId1:my_totalThe condition can only use the fields of the selected datasets: it cannot query other tables.
Common Settings
- Value mode: Count (default) or Percentage.
- Threshold: Static (default), relative, or dynamic. See Thresholds.
- Scan mode: Full dataset (default) or incremental. See Scan Modes.
- Where clause and group by: See Where Clause, Group By, and Joins.
Monitor as Code
The monitor kind is SqlCondition. The following YAML creates the monitor of the example:
kind: SqlCondition
sql: DATEDIFF(day, created_at, shipped_at) > 7
threshold:
kind: Static
valueMode: Percentage
max: 5%
timeWindow:
field: created_at
firstRun: P365D
frequency: P1DThe condition cannot contain SELECT, and a monitor can join at most two datasets. See the Parameters reference for the field syntax, joins, and examples.
Related Templates
- No-Code Condition: Builds the same kind of rule in a visual editor.
- SQL Query: Runs a full SQL query when a per-row condition is not enough.
Updated 7 days ago

