📖 Story
Duolingo · Learner Engagement
Monday morning at Duolingo's Learner Engagement team. The learning_activity table logs one row every time a user opens a lesson or uses a 'streak freeze' to protect their streak without actually studying — a freeze day still gets logged with a language and a date, but its xp_earned is NULL, not zero, because no lesson was completed. The team wants a per-user engagement summary: total XP, a fair daily average that doesn't quietly ignore freeze days, and which languages each learner is actively juggling.
🎯 Your Mission
For each user in learning_activity, calculate total_xp as the sum of xp_earned (treating a NULL xp_earned, from a streak-freeze day, as 0). Calculate avg_xp_per_day as the average xp_earned across all logged days for that user, also treating NULL as 0 — a freeze day should pull the average down, not be excluded from it. Calculate language_count as the number of distinct languages the user has activity for, and languages_list as those distinct language names joined into a single comma-separated string, sorted alphabetically. Return user_name, total_xp, avg_xp_per_day (rounded to 2 decimal places), language_count, and languages_list, sorted by total_xp in descending order.