SQL
Lab
Meta Meta Interview Question 10

Most Popular
Content Type

Find the most popular content type based on reactions.

Table Schema

Inspect
Table

interactive
ColumnType
post_idinteger
content_typevarchar
ColumnType
post_idinteger

Sample Data

Input
Output

Sample Input: posts
post_idcontent_type
1video
2image
3video
4text
Sample Input: reactions
post_id
1
1
2
3
3
3
4
Expected Output
content_typetotal_reactions
video5

SQL Editor

Run
Query

postgresql
Waiting for query

content_typetotal_reactions
video5

Hints

Unlock
Clues

Hint 01: Identify the grouping level required by the output.
Hint 02: Aggregate with COUNT, SUM, AVG, or a window function as needed.
Hint 03: Filter after aggregation with HAVING or after ranking with an outer query.

Solution

Locked
Answer

Solution is locked until you decide to reveal it. Try the editor first, then open this when you want the reference answer.

SELECT p.content_type, COUNT(*) AS total_reactions
FROM reactions r
JOIN posts p ON r.post_id = p.post_id
GROUP BY p.content_type
ORDER BY total_reactions DESC
LIMIT 1;

Explanation

Step By
Step

01

Read the expected output columns to determine the final grain.

02

Aggregate or rank the input rows to calculate the requested metric.

03

Filter, sort, and alias the final columns to match the output.

Related Questions

Keep
Solving