Count Active Projects as of a Given Date

Quick Overview

A SQL question that asks you to count the projects marked In Progress whose start and end dates cover June 1, 2024, returned as one column. It tests filtering on a status and an inclusive date window, and making sure the query still returns 0 when no project matches.

Count Active Projects as of a Given Date

Company: Target

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Count the projects in `Projects` that are in progress as of `2024-06-01`. A project is in progress when `status = 'In Progress'` AND `start_date <= '2024-06-01'` AND `end_date >= '2024-06-01'`. Return the count in a single column named `active_projects`. ```hint Empty result Check what your query returns when no project meets all three conditions. ``` ### Input Table(s) `Projects` | Column | Type | Meaning | |---|---|---| | project_id | INT | Project identifier | | project_name | VARCHAR(100) | Project name | | status | VARCHAR(20) | Project state: 'In Progress', 'Completed', 'Planned' or 'Cancelled' | | start_date | DATE | First day of the project | | end_date | DATE | Last day of the project | Primary key: `project_id`. ### Output Contract - Exactly one row with one column, `active_projects` (integer): the number of projects in progress on 2024-06-01. - The result is a single row, so no ordering applies. - No rounding. When no project qualifies, return one row with `0`. ### Example `Projects` | project_id | project_name | status | start_date | end_date | |---|---|---|---|---| | 1 | Website Redesign | In Progress | 2024-05-01 | 2024-08-31 | | 2 | Mobile App | In Progress | 2024-01-01 | 2024-05-15 | | 3 | Data Migration | Completed | 2024-02-01 | 2024-04-30 | | 4 | AI Research | In Progress | 2024-06-01 | 2024-12-31 | | 5 | Marketing Campaign | Planned | 2024-07-01 | 2024-09-30 | Expected result: | active_projects | |---| | 2 | Projects 1 and 4 are 'In Progress' and their date ranges include 2024-06-01. Project 4 starts on that exact day, which counts because both bounds are inclusive. Project 2 is 'In Progress' but ended on 2024-05-15, and projects 3 and 5 have other statuses. ### Constraints and Clarifications - The table holds between 1 and 10,000 projects. - `status` is always one of 'In Progress', 'Completed', 'Planned' or 'Cancelled', spelled exactly as shown. - `start_date <= end_date` for every project. - Both date bounds are inclusive: a project that starts or ends on 2024-06-01 is in progress on that day. - `project_id` is the primary key, so each row is a distinct project. - If no project qualifies, return `0`, not an empty result.

Overview: A SQL question that asks you to count the projects marked In Progress whose start and end dates cover June 1, 2024, returned as one column. It tests filtering on a status and an inclusive date window, and making sure the query still returns 0 when no project matches.

Target logo
Target
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Count the projects in Projects that are in progress as of 2024-06-01. A project is in progress when status = 'In Progress' AND start_date <= '2024-06-01' AND end_date >= '2024-06-01'. Return the count in a single column named active_projects.

Input Table(s)

Projects

ColumnTypeMeaning
project_idINTProject identifier
project_nameVARCHAR(100)Project name
statusVARCHAR(20)Project state: 'In Progress', 'Completed', 'Planned' or 'Cancelled'
start_dateDATEFirst day of the project
end_dateDATELast day of the project

Primary key: project_id.

Output Contract

  • Exactly one row with one column, active_projects (integer): the number of projects in progress on 2024-06-01.
  • The result is a single row, so no ordering applies.
  • No rounding. When no project qualifies, return one row with 0 .

Example

Projects

project_idproject_namestatusstart_dateend_date
1Website RedesignIn Progress2024-05-012024-08-31
2Mobile AppIn Progress2024-01-012024-05-15
3Data MigrationCompleted2024-02-012024-04-30
4AI ResearchIn Progress2024-06-012024-12-31
5Marketing CampaignPlanned2024-07-012024-09-30

Expected result:

active_projects
2

Projects 1 and 4 are 'In Progress' and their date ranges include 2024-06-01. Project 4 starts on that exact day, which counts because both bounds are inclusive. Project 2 is 'In Progress' but ended on 2024-05-15, and projects 3 and 5 have other statuses.

Constraints and Clarifications

  • The table holds between 1 and 10,000 projects.
  • status is always one of 'In Progress', 'Completed', 'Planned' or 'Cancelled', spelled exactly as shown.
  • start_date <= end_date for every project.
  • Both date bounds are inclusive: a project that starts or ends on 2024-06-01 is in progress on that day.
  • project_id is the primary key, so each row is a distinct project.
  • If no project qualifies, return 0 , not an empty result.