Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Pandas Conditional Labeling

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Pandas Conditional Labeling. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Impact Analytics is preparing workforce profile data for an internal segmentation report. Write a PostgreSQL query that classifies each profile according to age.

Write a SQL query to return every profile's id, original age, and a new age_group column. The age_group must be major when age is greater than 18. Otherwise, it must be minor. Treat ages of exactly 18, negative test values, and NULL ages as minor because they do not satisfy the greater-than condition.

Requirements

  1. Use a CASE WHEN expression to create age_group.
  2. Return all rows ordered by id in ascending order.

Schema

workforce_profiles
ColumnTypeDescription
idPKINTEGERUnique workforce profile identifier
ageINTEGERProfile age, which may be NULL
Tablesworkforce_profiles
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results