Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Return each department_id and the average salary of the employees in it, as a column named avg_salary.
Same grouping idea as counting, but with a different aggregate — AVG instead of COUNT.
employees(department_id, salary): (1,120000),(1,110000),(1,105000),(2,90000),(2,95000),(3,80000)
(1, 111666.67), (2, 92500.0), (3, 80000.0)
Department 1's three salaries average (120000+110000+105000)/3 = 111666.67; department 2 averages (90000+95000)/2 = 92500; department 3 has one salary, 80000.