SQL Functions and Aggregation/Convert a value to NULL conditionally

Return NULL when two expressions are equal.

Section: Conditional, NULL, and Conversion Functions

Convert a value to NULL conditionally

sql
sql
SELECT revenue / NULLIF(order_count, 0) AS revenue_per_order
FROM daily_metrics;
Explanation

NULLIF is often used to avoid divide-by-zero errors.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Conditional, NULL, and Conversion Functions
Replace NULL with fallback value
Return the first non-NULL value in a list.
OpenIn sheetsqlsame section
Use CASE expression
Return different values based on conditions.
OpenIn sheetsqlsame section
Convert data types
Cast an expression to a different type.
OpenIn sheetsqlsame section
Concatenate strings
Join multiple strings into one value.
Get current date and timestamp
Return the current date and current timestamp.
Count distinct values
Count unique entries in a column.