LinkedIn: Learning Course Completions per Category in Q1 2025

Easy
729.

LinkedIn: Learning Course Completions per Category in Q1 2025

The LinkedIn Learning content team reviews which course categories learners actually finished in the first quarter.

For every category that appears in Course, return category and completions, the number of enrollments in that category's courses with completed_on between 2025-01-01 and 2025-03-31 inclusive. A category with no completion in that window shows 0. Order the rows by completions descending, then category ascending.

A practice scenario set at LinkedIn: the tables and data are invented, and this is not a question from, or endorsed by, LinkedIn.

Tables

Table: Course

ColumnType
course_idint
titlevarchar
categoryvarchar

Primary key: course_id.

One row per course; several courses share a category.

Table: CourseEnrollment

ColumnType
enrollment_idint
member_idint
course_idint
enrolled_ondate
completed_ondate

Primary key: enrollment_id.

completed_on is NULL until the learner finishes the course.

Example

The rows must come back in the order shown.

Course

course_idtitlecategory
1SQL Essential TrainingData Science
2Python for Data AnalysisData Science
3Leading Without AuthorityLeadership
4Agile FoundationsProject Management
5Content Marketing BasicsMarketing

CourseEnrollment

enrollment_idmember_idcourse_idenrolled_oncompleted_on
12112024-12-202025-01-01
22222025-02-012025-03-31
32312025-03-102025-04-01
42432025-01-052025-02-14
52532025-01-20NULL
62642024-11-022024-12-31
72752025-02-112025-03-02

Output

categorycompletions
Data Science2
Leadership1
Marketing1
Project Management0
Read the hints, the editorial and the reference solution
-- Write your MySQL query below

Sign in to write, run and submit queries

A free account — no card, no trial clock. You come straight back here.

Run your query to see its result next to the expected one, example by example.

LinkedIn: Learning Course Completions per Category in Q1 2025

The LinkedIn Learning content team reviews which course categories learners actually finished in the first quarter.

  • Difficulty: Easy
  • Topics: Joins, Aggregation, Dates
  • Dialect: MySQL
  • Problem: #729

Problem statement

The LinkedIn Learning content team reviews which course categories learners actually finished in the first quarter.

For every category that appears in Course, return category and completions, the number of enrollments in that category's courses with completed_on between 2025-01-01 and 2025-03-31 inclusive. A category with no completion in that window shows 0. Order the rows by completions descending, then category ascending.

A practice scenario set at LinkedIn: the tables and data are invented, and this is not a question from, or endorsed by, LinkedIn.

Tables

Table: Course

ColumnType
course_idint
titlevarchar
categoryvarchar

Primary key: course_id.

One row per course; several courses share a category.

Table: CourseEnrollment

ColumnType
enrollment_idint
member_idint
course_idint
enrolled_ondate
completed_ondate

Primary key: enrollment_id.

completed_on is NULL until the learner finishes the course.

Examples

Example 1

Course

course_idtitlecategory
1SQL Essential TrainingData Science
2Python for Data AnalysisData Science
3Leading Without AuthorityLeadership
4Agile FoundationsProject Management
5Content Marketing BasicsMarketing

CourseEnrollment

enrollment_idmember_idcourse_idenrolled_oncompleted_on
12112024-12-202025-01-01
22222025-02-012025-03-31
32312025-03-102025-04-01
42432025-01-052025-02-14
52532025-01-20NULL
62642024-11-022024-12-31
72752025-02-112025-03-02

Output

categorycompletions
Data Science2
Leadership1
Marketing1
Project Management0

How to solve LinkedIn: Learning Course Completions per Category in Q1 2025

Every category must be listed, even the ones with no completions, so the query starts from Course and LEFT JOINs the enrollments. The quarter condition goes into the ON clause: it decides which enrollments attach to a course, while a course with none still keeps one row with NULLs. COUNT(e.enrollment_id) then counts only the attached enrollments, giving 0 for such a category. Putting the date test in WHERE instead would discard the NULL rows and lose exactly the categories the question insists on.

NULL completed_on values fail BETWEEN, so unfinished enrollments never count, and both 2025-01-01 and 2025-03-31 are inside the window. The first alternative keeps every enrollment in the join and counts conditionally with SUM(CASE …); the second computes each category's count in a correlated subquery over the distinct categories, testing the quarter with QUARTER() and YEAR(). Grouping by category merges all of its courses.

Reference solution (MySQL)

SELECT c.category, COUNT(e.enrollment_id) AS completions
FROM Course c
LEFT JOIN CourseEnrollment e
  ON e.course_id = c.course_id
 AND e.completed_on BETWEEN '2025-01-01' AND '2025-03-31'
GROUP BY c.category
ORDER BY completions DESC, c.category

Another way

SELECT c.category,
       SUM(CASE WHEN e.completed_on >= '2025-01-01' AND e.completed_on < '2025-04-01' THEN 1 ELSE 0 END) AS completions
FROM Course c LEFT JOIN CourseEnrollment e ON e.course_id = c.course_id
GROUP BY c.category
ORDER BY completions DESC, c.category

Another way

SELECT cat.category,
       (SELECT COUNT(*) FROM CourseEnrollment e JOIN Course c ON c.course_id = e.course_id
        WHERE c.category = cat.category AND QUARTER(e.completed_on) = 1 AND YEAR(e.completed_on) = 2025) AS completions
FROM (SELECT DISTINCT category FROM Course) cat
ORDER BY completions DESC, cat.category

← LinkedIn: InMail Response Rate per Recruiter · LinkedIn: Easy Apply Share of Applications per Job →