Sobes.tech
Intern

Write an SQL query to calculate the average salary for each employee per year. The table contains fields: fio, date, amount (salary)

sobes.tech AI

Answer from AI

sql SELECT fio, AVG(amount) AS average_salary_per_month, EXTRACT(YEAR FROM date) AS year FROM salary_table GROUP BY fio, EXTRACT(YEAR FROM date) ORDER BY fio, year;


This query groups records by employee (fio) and year, calculating the average salary per month for each year. If you need the average salary for the entire year, you can use the sum and divide by the number of months with payments.