👏👏👏
Data Analyst | Senior Undergrad | EDA | Python | SQL | Excel | PowerBI | Git | GitHub | --Face your failures with a smile :)
SQL Query Breakdown: Time Spent Sending vs. Opening Snaps by Age Group Recently, I worked on an interesting analysis to breakdown the time spent sending vs. opening snaps across different age groups. The goal was to determine what percentage of the total time spent is dedicated to each activity within these age buckets. Problem: Given a dataset of user activities, I wanted to find the proportion of time each age group spends on sending and opening snaps, as a percentage of the total time spent on these two activities. Thought Process: Data Aggregation: I started by grouping the data by the age_bucket from the age_breakdown table, as we needed the age groups for each user. Activity Filtering: I filtered the activities to focus only on two types: sending and opening snaps. Using the CASE statements allowed me to sum the time_spent for each activity type. Percentage Calculation: I calculated the percentage of time spent sending and opening by dividing the individual activity time by the total time spent on both activities for each age group. Rounding: I used ROUND() to ensure the percentages are displayed with two decimal places for clearer interpretation. Why I Used LEFT JOIN: I opted for a LEFT JOIN between the activities and age_breakdown tables to ensure that all users’ activities are included in the analysis, even if some users might not have an age bucket assigned. This guarantees that the data is as comprehensive as possible while preserving missing values where necessary. You can find the question on Dataford. link: https://lnkd.in/gNRnpkVT How do you approach calculating percentages in SQL? Share your thoughts below! Shane Butler , Venkata Naga Sai Kumar Bysani, Abhisek Sahu, Prithvi S., Abhinav Singh #SQL #DataAnalysis #DataScience #Analytics #DataDriven #BusinessIntelligence