SQL QuestSQL Interview Questions › Conditional Logic

Building Age Tier

EasyFreeQuerying BasicsConditional Logic

Categorize each Manhattan property by age_tier: 'Pre-War' if year_built < 1945, 'Mid-Century' if 1945-1979, 'Modern' if 1980-1999, 'Contemporary' if 2000+. Skip properties with year_built = 0 (unknown). The borough column uses 'MN' for Manhattan. Show address, year_built, age_tier. Order by year_built ASC, then address alphabetically for ties.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

properties

bblboroughaddresszipbldg_classland_useyear_builtnum_floorsunits_residentialunits_totallot_area_sqftbldg_area_sqftassess_totalowner_namelatitudelongitude
1009720001MN240 1 AVENUE10009D74194513.00000008764881226750008942176790924050.00000BPP ST OWNER LLC40.7317236-73.9778964
1009950005MN1472 BROADWAY10036O45199851.000000002458001642675489648150.00000NYC ECONOMIC DEVELOPMENT CORPORATION40.7560214-73.9857642
1010070029MN1345 AVENUE OF THE AMER10105O95196849.0000000050903751931978429758550.000001345 LEASEHOLD LLC40.7630634-73.9792541

Expected output: Each labeled Pre-War / Mid-Century / Modern / Contemporary

Hint

CASE WHEN year_built < 1945 THEN 'Pre-War' WHEN year_built < 1980 THEN 'Mid-Century' WHEN year_built < 2000 THEN 'Modern' ELSE 'Contemporary' END

Concepts

SELECT CASE WHERE

Practise the topic: SQL practice questions · CASE WHEN practice

Related questions

Calculated ColumnsEasy · FreeComp Tier LabelsEasy · FreeMembership Display LabelsEasy · FreeRounded Revenue: Top 10 from 2015+Easy · FreeAsset Tier ClassificationEasy · FreeTool Wear Stress TierEasy · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test