Table: post
+--------------+---------+ | Column Name | Type | +--------------+---------+ | post_id | int | | view_id | int | | relationship | varchar | | post_date | date | +--------------+---------+
post_idis the primary key.relationshipis one of'friend'or'unconnected'.
Table: interaction
+------------------+---------+ | Column Name | Type | +------------------+---------+ | post_id | int | | interaction_type | varchar | +------------------+---------+Multiple rows per
post_idare 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; theLEFT JOINpreserves it with a reaction count of 0.