SQL
Lab
LinkedIn Easy CTE Percent

Duplicate
Listing
Percent

Calculate the percentage of job listings that are duplicates.

Table Schema

Inspect
Table

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

Sample Data

Input
Output

Sample Input: job_listings
job_idcompany_idtitledescriptionlocationsalaryposted_date
11AnalystWork on dataNY600002024-01-01
21AnalystWork on dataNY620002024-01-02
32EngineerBuild systemsTX900002024-01-03
42EngineerBuild systemsTX920002024-01-04
53ManagerLead teamCA1000002024-01-05
64AnalystAnalyze reportsSF700002024-01-06
Expected Output
duplicate_percentage
33.33

SQL Editor

Run
Query

postgresql
Waiting for query

duplicate_percentage
33.33

Hints

Unlock
Clues

Hint 01: Build duplicate groups with GROUP BY company_id, title, description.
Hint 02: Groups with COUNT(*) > 1 are duplicate groups.
Hint 03: Compute duplicate rows divided by total rows and multiply by 100.

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.

WITH duplicate_rows AS (
  SELECT
    COUNT(*) AS duplicate_count
  FROM job_listings
  GROUP BY company_id, title, description
  HAVING COUNT(*) > 1
)
SELECT
  ROUND(SUM(duplicate_count) * 100.0 / (SELECT COUNT(*) FROM job_listings), 2) AS duplicate_percentage
FROM duplicate_rows;

Explanation

Step By
Step

01

Find duplicate groups using company_id, title, and description.

02

Sum the rows inside those duplicate groups.

03

Divide by the total number of listings and round to two decimals.

Related Questions

Keep
Solving