Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 759 Bytes

File metadata and controls

19 lines (16 loc) · 759 Bytes

1440. Evaluate Boolean Expression

Solution: Join, CASE, IF

Join Expressions with Variables twice: One for the left_operand and one for the right_operand.
Use a case statement to choose how to compare the two values.
Use an if statement to select true or false depending on how the expression evaluates.

SELECT left_operand, operator, right_operand,
CASE
  WHEN operator = '>' THEN IF(left_val.value > right_val.value, 'true', 'false')
  WHEN operator = '<' THEN IF(left_val.value < right_val.value, 'true', 'false')
  ELSE IF(left_val.value = right_val.value, 'true', 'false')
END AS value
FROM Expressions
JOIN Variables AS left_val ON left_val.name = left_operand
JOIN Variables AS right_val ON right_val.name = right_operand;