A project tracker stores issues and merge requests. Both can carry any number of labels from one shared labels table, linked through the join tables issue_labels and merge_request_labels.
Find all issues that have both the bug and urgent labels (issues with only one of them are excluded). Return issue_id, issue_title, and labels: a comma-separated list of the matching label names sorted alphabetically.
Input Table(s)
Table issues, primary key issue_id:
| Column | Type | Meaning |
|---|
| issue_id | INTEGER | Unique issue id |
| issue_title | TEXT | Title of the issue |
Table merge_requests, primary key merge_request_id:
| Column | Type | Meaning |
|---|
| merge_request_id | INTEGER | Unique merge request id |
| merge_request_title | TEXT | Title of the merge request |
Table labels, primary key label_id:
| Column | Type | Meaning |
|---|
| label_id | INTEGER | Unique label id |
| name | TEXT | Label name as shown in the tracker, such as bug |
Table issue_labels, primary key (issue_id, label_id):
| Column | Type | Meaning |
|---|
| issue_id | INTEGER | References issues.issue_id |
| label_id | INTEGER | References labels.label_id |
Table merge_request_labels, primary key (merge_request_id, label_id):
| Column | Type | Meaning |
|---|
| merge_request_id | INTEGER | References merge_requests.merge_request_id |
| label_id | INTEGER | References labels.label_id |
Output Contract
One row per qualifying issue, with exactly these columns:
| Column | Type | Meaning |
|---|
| issue_id | INTEGER | The issue |
| issue_title | TEXT | Its title |
| labels | TEXT | The matching label names in alphabetical order, joined by a comma and a space |
Only bug and urgent can match, so labels is bug, urgent for every qualifying issue. Sort the rows by issue_id ascending. No rounding applies.
Example
labels:
| label_id | name |
|---|
| 1 | bug |
| 2 | urgent |
| 3 | frontend |
| 4 | docs |
| 5 | bug |
issues:
| issue_id | issue_title |
|---|
| 1 | Login page crashes on submit |
| 2 | Typo in the README |
| 3 | Payment webhook times out |
| 4 | Dark mode colors are off |
issue_labels:
| issue_id | label_id |
|---|
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 2 |
| 2 | 4 |
| 3 | 2 |
| 3 | 5 |
| 4 | 1 |
| 4 | 5 |
merge_requests:
| merge_request_id | merge_request_title |
|---|
| 2 | Retry webhook delivery |
merge_request_labels:
| merge_request_id | label_id |
|---|
| 2 | 1 |
| 2 | 2 |
Expected result:
| issue_id | issue_title | labels |
|---|
| 1 | Login page crashes on submit | bug, urgent |
| 3 | Payment webhook times out | bug, urgent |
Issue 1 qualifies, and its frontend label stays out of labels. Issue 2 has only urgent. Merge request 2 carries both labels, but it is a merge request, so it does not make issue 2 qualify. Issue 3 qualifies through label 5, a second label row named bug. Issue 4 has two bug label rows and no urgent, so it is excluded.
Constraints and Clarifications
-
labels
has at most 100 rows.
issues
and
merge_requests
have at most 10,000 rows each.
-
(issue_id, label_id)
and
(merge_request_id, label_id)
pairs are unique.
-
Label names are matched exactly as stored, in lowercase:
bug
and
urgent
.
-
Two label rows can share a name (label ids 1 and 5 in the example). The condition is about names: an issue qualifies when both
bug
and
urgent
appear among its label names, and each name appears once in
labels
.
-
An issue can carry other labels as well. It still qualifies, and the other labels do not appear in
labels
.
-
An issue with no labels never qualifies. None of the columns used here contain NULLs.
-
Only
issue_labels
decides the result. Labels attached to merge requests do not count.