Count users who posted one job title versus several distinct job titles

Quick Overview

Write a SQL query that groups job postings by user, counts each user's distinct job titles, and returns one row with how many users posted a single title and how many posted several. It tests two-level aggregation, COUNT DISTINCT and conditional counting.

Count users who posted one job title versus several distinct job titles

Company: LinkedIn

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Count users by the number of distinct `job_title` values they posted. Return one row with `same_job` (users with exactly one distinct title) and `different_jobs` (users with more than one distinct title). ```hint Count at the right grain Decide what a single row per user should hold before you count users, and remember that posting the same title twice is still one title. ``` ### Input Table(s) `job_postings` | column | type | meaning | |---|---|---| | id | INTEGER | Posting identifier (primary key) | | job_title | VARCHAR(255) | Title of the job posted, never NULL | | user_id | INTEGER | User who posted the job, never NULL | | date_posted | TIMESTAMP | When the job was posted | ### Output Contract Return exactly one row with these columns, in this order: | column | meaning | |---|---| | same_job | Number of users with exactly one distinct `job_title` | | different_jobs | Number of users with more than one distinct `job_title` | Both values are integer counts. The result is always a single row, so no ordering applies. ### Example `job_postings` | id | job_title | user_id | date_posted | |---|---|---|---| | 1 | Software Engineer | 101 | 2024-01-10 09:00:00 | | 2 | Software Engineer | 101 | 2024-01-15 10:00:00 | | 3 | Data Analyst | 102 | 2024-01-12 11:00:00 | | 4 | Product Manager | 102 | 2024-01-13 12:00:00 | | 5 | Designer | 103 | 2024-01-14 13:00:00 | Expected result: | same_job | different_jobs | |---|---| | 2 | 1 | User 101 posted only "Software Engineer" (1 distinct title) and user 103 posted only "Designer" (1 distinct title), so `same_job` is 2. User 102 posted 2 distinct titles, so `different_jobs` is 1. ### Constraints and Clarifications - The table has between 1 and 100,000 rows. - `id` is unique. `user_id` and `job_title` are never NULL, so every user has at least one distinct title and falls into exactly one of the two counts. - A user may post the same job title multiple times. Repeats of one title count as a single distinct title. - Titles are compared exactly as stored. - `date_posted` does not affect the answer.

Overview: Write a SQL query that groups job postings by user, counts each user's distinct job titles, and returns one row with how many users posted a single title and how many posted several. It tests two-level aggregation, COUNT DISTINCT and conditional counting.

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

Count users by the number of distinct job_title values they posted. Return one row with same_job (users with exactly one distinct title) and different_jobs (users with more than one distinct title).

Input Table(s)

job_postings

columntypemeaning
idINTEGERPosting identifier (primary key)
job_titleVARCHAR(255)Title of the job posted, never NULL
user_idINTEGERUser who posted the job, never NULL
date_postedTIMESTAMPWhen the job was posted

Output Contract

Return exactly one row with these columns, in this order:

columnmeaning
same_jobNumber of users with exactly one distinct job_title
different_jobsNumber of users with more than one distinct job_title

Both values are integer counts. The result is always a single row, so no ordering applies.

Example

job_postings

idjob_titleuser_iddate_posted
1Software Engineer1012024-01-10 09:00:00
2Software Engineer1012024-01-15 10:00:00
3Data Analyst1022024-01-12 11:00:00
4Product Manager1022024-01-13 12:00:00
5Designer1032024-01-14 13:00:00

Expected result:

same_jobdifferent_jobs
21

User 101 posted only "Software Engineer" (1 distinct title) and user 103 posted only "Designer" (1 distinct title), so same_job is 2. User 102 posted 2 distinct titles, so different_jobs is 1.

Constraints and Clarifications

  • The table has between 1 and 100,000 rows.
  • id is unique. user_id and job_title are never NULL, so every user has at least one distinct title and falls into exactly one of the two counts.
  • A user may post the same job title multiple times. Repeats of one title count as a single distinct title.
  • Titles are compared exactly as stored.
  • date_posted does not affect the answer.