Each row of job_postings is one posting of a job, and a job can be posted several times. Using the fixed reference date 2024-06-30, consider only postings from the last 180 days, and for each job keep only its most recent posting in that window (by post_dt). Compute the percentage of those latest postings whose status is REVOKED, rounded to 2 decimals, as revoked_percentage.
Input Table(s)
Table job_postings, primary key posting_id:
| Column | Type | Meaning |
|---|
| posting_id | INT | Posting identifier |
| job_id | INT | Job that was posted, NOT NULL |
| company_id | INT | Company that owns the job, NOT NULL (not needed for this task) |
| post_dt | DATE | Date of the posting, NOT NULL |
| status | VARCHAR(20) | ACTIVE or REVOKED, NOT NULL |
Output Contract
| Column | Meaning |
|---|
| revoked_percentage | Percentage (0 to 100 scale) of jobs whose latest posting in the window is REVOKED, rounded to 2 decimals |
The result is exactly one row with one column, so no ordering is needed.
Example
job_postings:
| posting_id | job_id | company_id | post_dt | status |
|---|
| 1 | 100 | 10 | 2024-06-01 | ACTIVE |
| 2 | 100 | 10 | 2024-06-15 | REVOKED |
| 3 | 101 | 11 | 2024-05-20 | ACTIVE |
| 4 | 102 | 12 | 2024-06-25 | REVOKED |
| 5 | 103 | 13 | 2024-01-01 | REVOKED |
Expected output:
The window runs from 2024-01-02 to 2024-06-30. Job 100's latest posting is posting 2 (2024-06-15, REVOKED), job 101's is posting 3 (ACTIVE) and job 102's is posting 4 (REVOKED). Job 103's only posting, on 2024-01-01, falls one day before the window and is ignored. Two of the three jobs are revoked, so the result is 66.67.
Constraints and Clarifications
-
The table holds 1 to 10,000 postings.
status
is exactly
ACTIVE
or
REVOKED
, and every
post_dt
is on or before 2024-06-30.
-
"The last 180 days" means 2024-06-30 minus 180 days through 2024-06-30, both ends inclusive: 2024-01-02 to 2024-06-30.
-
The percentage is over jobs. Each job with at least one posting in the window counts once, through its latest posting there. Postings outside the window are ignored, and a job with no posting in the window is not counted at all.
-
If two postings of the same job share the latest
post_dt
, the one with the larger
posting_id
is the latest.
-
If no posting falls in the window, return one row whose
revoked_percentage
is NULL.