Category: Conditionals
NULLIF
NULLIF returns NULL if both expressions are equal, otherwise the first expression.
Syntax
NULLIF(expr1, expr2)AMC specifics
- Classic use: avoid division by zero by turning a zero denominator into NULL.
- The division then returns NULL instead of an error.
Example
Click-through rate without an error at zero impressions.
SELECT
campaign,
SUM(clicks) / NULLIF(SUM(impressions), 0) AS ctr
FROM
sponsored_ads_traffic
GROUP BY
1 Checked against the AMC schema, not executed on an AMC instance.