KatInterview

MySQL Expression Results

SQL & DataAuto-graded · 16 test cases
MediumAuto-gradedSQL & Datatype-coercionsqlboolean-logic

Last updated

Tests understanding of MySQL type coercion, boolean evaluation, and string comparison functions.

You are given a list of expression identifiers, each corresponding to one of four MySQL expressions. Your task is to return what each expression evaluates to in MySQL 8.0.

The four expressions are:

  1. SELECT '0' = 0;
  2. SELECT 0 IS FALSE;
  3. SELECT '0' IS FALSE;
  4. SELECT STRCMP('0', 0);

Given a list of expression IDs (integers 1 through 4), return a list of their evaluated results in the same order.

Remember that MySQL represents boolean results as integers: TRUE is 1 and FALSE is 0.

Constraints

  • 1 <= len(expression_ids) <= 100
  • Each expression ID is an integer from 1 to 4
  • Expression IDs may repeat in the input
  • The output order must match the input order

Examples

Example 1

Input: mysql_expression_results([1, 2, 3, 4])

Output: [1, 1, 1, 0]

Example 2

Input: mysql_expression_results([4, 1, 3])

Output: [0, 1, 1]

Example 3

Input: mysql_expression_results([2, 2, 4])

Output: [1, 1, 0]

Hints

Hint 1

MySQL converts strings to numbers when comparing them with numeric values or evaluating them in boolean contexts.

Hint 2

The STRCMP function compares strings and returns 0 when they are equal, -1 when the first is less, and 1 when the first is greater.

Hint 3

In MySQL, the integer 0 is considered FALSE, and any non-zero value is TRUE. The IS FALSE operator returns 1 (true) if its operand is false.