LinkedIn: Invitation Acceptance With and Without a Note

Medium
732.

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.

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

ColumnTypeValues
invitation_idint
sender_idint
recipient_idint
sent_ondate
has_notebool
statusenumpending, accepted, ignored, withdrawn

Primary key: invitation_id.

One row per connection invitation; has_note is 1 when the sender added a personal message.

Example

The rows may come back in any order; the columns must be the ones shown, in that order.

Invitation

invitation_idsender_idrecipient_idsent_onhas_notestatus
111212025-05-011accepted
211222025-05-011accepted
312232025-05-021ignored
412242025-05-031pending
513252025-05-030accepted
613262025-05-040ignored
714272025-05-050ignored
814282025-05-050withdrawn
915292025-05-060ignored

Output

invitation_typedecidedacceptedacceptance_pct
with note3266.7
without note4125
Read the hints, the editorial and the reference solution
-- Write your MySQL query below

Sign in to write, run and submit queries

A free account — no card, no trial clock. You come straight back here.

Run your query to see its result next to the expected one, example by example.

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

ColumnType
invitation_idint
sender_idint
recipient_idint
sent_ondate
has_notebool
statusenum(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_idsender_idrecipient_idsent_onhas_notestatus
111212025-05-011accepted
211222025-05-011accepted
312232025-05-021ignored
412242025-05-031pending
513252025-05-030accepted
613262025-05-040ignored
714272025-05-050ignored
814282025-05-050withdrawn
915292025-05-060ignored

Output

invitation_typedecidedacceptedacceptance_pct
with note3266.7
without note4125

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_type

Another 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(*) > 0

Another 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 →