SQL
Lab
LinkedIn Easy Group By Distinct

Multi Role
Hiring
Firms

Find companies hiring for more than 3 distinct job titles.

Table Schema

Inspect
Table

interactive
ColumnTypeDescription
job_idintegerUnique job posting identifier.
company_idintegerIdentifier for the company posting the job.
titlestringJob listing title.
departmentstringDepartment for the role.
locationstringJob location.
salaryintegerListed salary.
posted_datedateDate the job was posted.

Sample Data

Input
Output

Sample Input: job_listings
job_idcompany_idtitledepartmentlocationsalaryposted_date
11AnalystDataNY600002024-01-01
21EngineerEngNY900002024-01-02
31ScientistDataSF1200002024-01-03
41ManagerOpsSF1100002024-01-04
52AnalystDataTX700002024-01-05
62EngineerEngTX950002024-01-06
Expected Output
company_id
1

SQL Editor

Run
Query

postgresql
Waiting for query

company_id
1

Hints

Unlock
Clues

Hint 01: Group by company_id so each company gets one row.
Hint 02: Use COUNT(DISTINCT title) to count unique roles.
Hint 03: Use HAVING COUNT(DISTINCT title) > 3.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT
  company_id
FROM job_listings
GROUP BY company_id
HAVING COUNT(DISTINCT title) > 3;

Explanation

Step By
Step

01

Group job listings by company_id.

02

Count each company's distinct job titles.

03

Keep only companies where that count is greater than 3.

Related Questions

Keep
Solving