Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

Table: post

+--------------+---------+
| Column Name  | Type    |
+--------------+---------+
| post_id      | int     |
| view_id      | int     |
| relationship | varchar |
| post_date    | date    |
+--------------+---------+

post_id is the primary key. relationship is one of 'friend' or 'unconnected'.

Table: interaction

+------------------+---------+
| Column Name      | Type    |
+------------------+---------+
| post_id          | int     |
| interaction_type | varchar |
+------------------+---------+

Multiple rows per post_id are allowed; each row is one reaction (like, comment, etc.).

For posts within the fixed seven-day window from 2026-06-17 through 2026-06-24 (inclusive), compute the average number of reactions per post, grouped by relationship. A reaction is any row in interaction whose post_id matches the post. Posts with no interactions contribute 0 to the average. Return relationship and avg_reactions (rounded to 2 decimals), sorted by relationship.

The result format is shown below.

Example

Input:

post table:
+---------+---------+--------------+------------+
| post_id | view_id | relationship | post_date  |
+---------+---------+--------------+------------+
| 1       | 10      | friend       | 2026-06-22 |
| 2       | 11      | friend       | 2026-06-21 |
| 3       | 12      | friend       | 2026-06-20 |
| 4       | 13      | unconnected  | 2026-06-22 |
| 5       | 14      | unconnected  | 2026-06-21 |
+---------+---------+--------------+------------+

interaction table:
+---------+------------------+
| post_id | interaction_type |
+---------+------------------+
| 1       | like             |
| 1       | comment          |
| 2       | like             |
| 3       | like             |
| 3       | comment          |
| 3       | like             |
| 4       | like             |
| 4       | comment          |
| 4       | like             |
| 4       | comment          |
+---------+------------------+

Output:

+--------------+---------------+
| relationship | avg_reactions |
+--------------+---------------+
| friend       | 2.0           |
| unconnected  | 2.0           |
+--------------+---------------+

Explanation:
Friend posts have 2, 1, and 3 reactions (avg = 2.0). Unconnected posts have 4 and 0 reactions (avg = 2.0). Post 5 has no interactions; the LEFT JOIN preserves it with a reaction count of 0.


Accepted
34/172
Acceptance Rate19.8%
Test Cases
Input
-
Output
-
Expected
-