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_name | salary | is_senior |
|---|---|---|
| John | 120000 | 1 |
| Alice | 85000 | 1 |
| Bob | 80000 | 0 |
| Carol | 60000 | 0 |
| David | 70000 | 0 |
| Emma | 95000 | 1 |
| Frank | 65000 | 0 |
| Grace | 90000 | 1 |
| Henry | 55000 | 0 |
| Ivy | 68000 | 0 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
WHERE Clause & Filtering
Practice SQL WHERE clauses with realistic boundary, NULL, text, date, exclusion, and production-filtering problems.
Basic SQL Functions
Practice production-oriented string cleanup, numeric transformations, NULL handling, tolerant conversion, and delimiter parsing.
ORDER BY & Sorting
Practice deterministic SQL ordering with tie-breakers, custom priorities, NULL placement, expressions, joined data, aggregates, and portable top-N patterns.
Open the interactive workspace and practice across SQL topics.