Case

Search for the first condition that evaluates to true and return its associated value. If none of the conditions match, null is returned.

PRQL

  1. from employees
  2. derive distance = case [
  3. city == "Calgary" => 0,
  4. city == "Edmonton" => 300,
  5. ]

SQL

  1. SELECT
  2. *,
  3. CASE
  4. WHEN city = 'Calgary' THEN 0
  5. WHEN city = 'Edmonton' THEN 300
  6. ELSE NULL
  7. END AS distance
  8. FROM
  9. employees

To set a default, a true condition can be used:

PRQL

  1. from employees
  2. derive distance = case [
  3. city == "Calgary" => 0,
  4. city == "Edmonton" => 300,
  5. true => "Unknown",
  6. ]

SQL

  1. SELECT
  2. *,
  3. CASE
  4. WHEN city = 'Calgary' THEN 0
  5. WHEN city = 'Edmonton' THEN 300
  6. ELSE 'Unknown'
  7. END AS distance
  8. FROM
  9. employees