SELECT
age_group,
AVG(app_usage_time_min_day) AS average_app_usage,
AVG(screen_on_time_hours_day) AS average_screen_hours,
AVG(data_usage_mb_day) AS average_usage_mb,
COUNT(CASE WHEN operating_system = 'Android' THEN user_id END) AS android_count,
COUNT(CASE WHEN operating_system = 'iOS' THEN user_id END) AS ios_count
FROM (
SELECT
user_id,
operating_system,
app_usage_time_min_day,
screen_on_time_hours_day,
data_usage_mb_day,
battery_drain_mah_day,
CASE
WHEN age BETWEEN 18 AND 24 THEN '18-24'
WHEN age BETWEEN 25 AND 34 THEN '25-34'
WHEN age BETWEEN 35 AND 44 THEN '35-44'
WHEN age BETWEEN 45 AND 54 THEN '45-54'
WHEN age >= 55 THEN '55+'
ELSE 'Unknown'
END AS age_group
FROM @kaggle.valakhorasani_mobile_device_usage_and_user_behavior_dataset.user_behavior_dataset
) AS subquery
GROUP BY age_group
ORDER BY age_group ASC;