Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL: Age and Salary Filtering
00:00
5 left

SQL: Age and Salary Filtering

EasySQL · PostgreSQL

Problem

Given a scenario, write an SQL query to retrieve customers with age between 20 and 30 and salary greater than a specific amount, so that an insurance campaign can be sent to them.

Asked in the 1st Round Technical Interview stage.

Use the customers and customer_financial_profiles tables. Apply a salary threshold of 75000.

Output

  1. Return one row per qualifying customer with customer_id, customer_name, age, and salary.
  2. Include ages from 20 through 30 and salaries strictly greater than 75000.
  3. Order by age ascending, salary descending, then customer_id ascending.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer's full name
ageINTCustomer age in years
emailVARCHAR(150)Customer email address
customer_financial_profiles
ColumnTypeDescription
profile_idPKINTUnique financial profile identifier
customer_idINTReferenced customer identifier
salaryNUMERIC(12,2)Annual customer salary
employment_statusVARCHAR(30)Current employment status
Tablescustomerscustomer_financial_profiles
Interviewer

Your question is SQL: Age and Salary Filtering. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.