Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Count Specific Names in SQL

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

Your question is Count Specific Names in SQL. Start with the requirements and the two tables 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

Transaction Network Services wants a quick validation query for employee records assigned to active operational units. Write a PostgreSQL query that counts employees whose exact first_name value is Jack and whose department is active.

Requirements

  1. Join employees to departments using department_id.
  2. Match the exact first name Jack, preserving PostgreSQL's case-sensitive comparison.
  3. Include only employees assigned to departments where is_active is TRUE.
  4. Return one row with the count aliased as jack_count.

Schema

employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
first_nameVARCHAR(100)Employee's first name
department_idINTAssigned department identifier
departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(150)TNS department name
is_activeBOOLEANWhether the department is currently active
Tablesemployeesdepartments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results