LinkedIn: Invitation Acceptance With and Without a Note
Before changing the invite dialog, the growth team checks whether adding a personal note makes an invitation more likely to be accepted.
- Difficulty: Medium
- Topics: Aggregation, Conditional Logic
- Dialect: MySQL
- Problem: #732
Problem statement
Before changing the invite dialog, the growth team checks whether adding a personal note makes an invitation more likely to be accepted.
Only decided invitations count — status accepted or ignored; pending and withdrawn ones are left out entirely. Group them into 'with note' (has_note = 1) and 'without note' (has_note = 0) and return invitation_type, decided, accepted and acceptance_pct (accepted ÷ decided × 100, rounded to one decimal place). A group with no decided invitations does not appear. Return the rows in any order.
A practice scenario set at LinkedIn: the tables and data are invented, and this is not a question from, or endorsed by, LinkedIn.
Tables
Table: Invitation
| Column | Type |
|---|---|
| invitation_id | int |
| sender_id | int |
| recipient_id | int |
| sent_on | date |
| has_note | bool |
| status | enum(pending, accepted, ignored, withdrawn) |
Primary key: invitation_id.
One row per connection invitation; has_note is 1 when the sender added a personal message.
Examples
Example 1
Invitation
| invitation_id | sender_id | recipient_id | sent_on | has_note | status |
|---|---|---|---|---|---|
| 1 | 11 | 21 | 2025-05-01 | 1 | accepted |
| 2 | 11 | 22 | 2025-05-01 | 1 | accepted |
| 3 | 12 | 23 | 2025-05-02 | 1 | ignored |
| 4 | 12 | 24 | 2025-05-03 | 1 | pending |
| 5 | 13 | 25 | 2025-05-03 | 0 | accepted |
| 6 | 13 | 26 | 2025-05-04 | 0 | ignored |
| 7 | 14 | 27 | 2025-05-05 | 0 | ignored |
| 8 | 14 | 28 | 2025-05-05 | 0 | withdrawn |
| 9 | 15 | 29 | 2025-05-06 | 0 | ignored |
Output
| invitation_type | decided | accepted | acceptance_pct |
|---|---|---|---|
| with note | 3 | 2 | 66.7 |
| without note | 4 | 1 | 25 |
How to solve LinkedIn: Invitation Acceptance With and Without a Note
The denominator is the heart of this question. A pending invitation has not been answered, and a withdrawn one never reached a decision, so counting them would drag both rates down for reasons that have nothing to do with the note. The WHERE status IN ('accepted', 'ignored') filter runs first, leaving only answered invitations.
The label is a CASE on has_note, and grouping by that alias forms the two groups. In each, COUNT(*) is the decided total and a conditional SUM counts the acceptances; the percentage is their ratio times 100, rounded last. A group that has no decided invitation simply has no rows after the filter, so it never forms — exactly the statement's rule.
The first alternative computes each group with its own aggregate and glues them with UNION ALL; an aggregate without GROUP BY always returns a row, so HAVING COUNT(*) > 0 is what drops an empty group. The second averages 100-or-0 per invitation, which is the same percentage. All of them read the table once per branch.
Reference solution (MySQL)
SELECT CASE WHEN has_note = 1 THEN 'with note' ELSE 'without note' END AS invitation_type,
COUNT(*) AS decided,
SUM(CASE WHEN status = 'accepted' THEN 1 ELSE 0 END) AS accepted,
ROUND(100 * SUM(CASE WHEN status = 'accepted' THEN 1 ELSE 0 END) / COUNT(*), 1) AS acceptance_pct
FROM Invitation
WHERE status IN ('accepted', 'ignored')
GROUP BY invitation_typeAnother way
SELECT 'with note' AS invitation_type, COUNT(*) AS decided, SUM(status = 'accepted') AS accepted, ROUND(100 * SUM(status = 'accepted') / COUNT(*), 1) AS acceptance_pct
FROM Invitation WHERE has_note = 1 AND status IN ('accepted', 'ignored') HAVING COUNT(*) > 0
UNION ALL
SELECT 'without note', COUNT(*), SUM(status = 'accepted'), ROUND(100 * SUM(status = 'accepted') / COUNT(*), 1)
FROM Invitation WHERE has_note = 0 AND status IN ('accepted', 'ignored') HAVING COUNT(*) > 0Another way
SELECT IF(has_note = 1, 'with note', 'without note') AS invitation_type, COUNT(*) AS decided, COUNT(CASE WHEN status = 'accepted' THEN 1 END) AS accepted,
ROUND(AVG(CASE WHEN status = 'accepted' THEN 100 ELSE 0 END), 1) AS acceptance_pct
FROM Invitation WHERE status <> 'pending' AND status <> 'withdrawn' GROUP BY IF(has_note = 1, 'with note', 'without note')← LinkedIn: Connection Count of Every Member · LinkedIn: Members Whose Profile Views Doubled in May →