Post Count Per User
How many posts has each user created, and who posts the most?
- Joins
- Aggregation
- HAVING
- Sorting
Challenge brief
Understand the request
Content Analytics wants to understand which users are the most prolific content creators on the platform.
Show post count per user — username, full name, and total post count for users with at least 1 post.
Return
- username
- full_name
- post_count
Constraints
- Return users who have created at least one post
- Show the highest post counts first and resolve ties consistently
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
users
user_idINTEGERusernameVARCHAR(50)first_nameVARCHAR(50)last_nameVARCHAR(50)
posts
post_idINTEGERuser_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Post counts come from counting rows in the posts table per user. User names are in users. JOIN on user_id, then GROUP BY user to count their posts.
Hint 2
INNER JOIN users to posts on user_id. GROUP BY user_id. COUNT(p.post_id) AS post_count. INNER JOIN already excludes zero-post users. ORDER BY post_count DESC.
Hint 3
Start with the tables that establish the result grain for question 2, select the required output aliases, and add the remaining joins, filters, aggregation, and ordering one clause at a time.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT u.username, u.first_name || ' ' || u.last_name AS full_name, COUNT(p.post_id) AS post_count FROM users u INNER JOIN posts p ON u.user_id = p.user_id GROUP BY u.user_id, u.username, u.first_name, u.last_name HAVING COUNT(p.post_id) >= 1 ORDER BY post_count DESC;Why this works
INNER JOIN automatically excludes alex_brown who has zero posts. GROUP BY must include all non-aggregated SELECT columns to satisfy SQL rules.
Success check
4 users — john_doe and jane_smith (2 posts each), mike_wilson and sarah_jones (1 each)
Expected result
Use this output to verify values, aliases, ordering, and row count.
| username | full_name | post_count |
|---|---|---|
| john_doe | John Doe | 2 |
| jane_smith | Jane Smith | 2 |
| mike_wilson | Mike Wilson | 1 |
| sarah_jones | Sarah Jones | 1 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Netflix
Independent Netflix-style streaming, subscription, catalog, ratings, and engagement SQL practice.
Airbnb
Independent Airbnb-style marketplace, booking, listing, payment, review, and guest analytics SQL practice.
Return to the complete interview preparation experience.