SELECT Statements SQL Topic exerciseMediumVerified answerSQLite + PostgreSQL + MySQL + SQL Server live · 1 guided

Boolean Expression in SELECT

Return first_name, salary, and is_senior as 1 when salary is above 80000, otherwise 0.

  • CASE expressions

Exercise brief

Understand the request

Compensation operations analyst A legacy consumer expects a numeric senior-pay flag beside each salary.

Add a column is_senior that is 1 when salary > 80000 and 0 otherwise. Show first_name, salary, and is_senior.

Return

  • Return first_name, salary, and is_senior.

Constraints

  • Use portable conditional projection rather than an engine-specific boolean.

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

employees

  • first_nameVARCHAR(50)
  • salaryINTEGER

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

There is no first-class BOOLEAN in many engines. The portable trick is to wrap a comparison in CASE … THEN 1 ELSE 0 END.

Hint 2

Strict inequality matters here: salary > 80000 (Bob at 80000 is NOT senior).

Hint 3

CASE WHEN salary > 80000 THEN 1 ELSE 0 END AS is_senior

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT first_name, salary, CASE WHEN salary > 80000 THEN 1 ELSE 0 END AS is_senior FROM employees;

Why this works

PostgreSQL has a real BOOLEAN type, but SQLite, MySQL and SQL Server return 0/1 from comparisons. The CASE-to-1/0 idiom is portable across all engines and matches what BI tools usually expect for binary flags.

Expected result

Use this output to verify values, aliases, ordering, and row count.

first_namesalaryis_senior
John1200001
Alice850001
Bob800000
Carol600000
David700000
Emma950001
Frank650000
Grace900001
Henry550000
Ivy680000

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Practice Online

Open the interactive workspace and practice across SQL topics.