SELECT users.users_id,
MAX(users.name) AS userName,
user_dolg.dogovor_name,
SUM(user_dolg.hours) AS hoursSum
FROM users
INNER JOIN user_dolg ON user_dolg.user_id = users.users_id
WHERE hours <> 'нет'
AND user_dolg.date BETWEEN '2020-01-01' AND '2021-01-01'
GROUP BY users.users_id,
user_dolg.dogovor_name
#1064 - У вас ошибка в запросе. Изучите документацию по используемой версии MySQL на предмет корректного синтаксиса около 'INT)
END
) AS hoursSum
FROM users
INNER JOIN user_dolg ON user_dolg.user_id ' на строке 9
SELECT user_dolg.user_id, users.users_id, users.name, user_dolg.dogovor_name, user_dolg.hours
FROM users
INNER JOIN user_dolg ON user_dolg.user_id = users.users_id
WHERE hours > 0 BETWEEN '2020-01-01' AND '2021-01-01'
GROUP BY users_id AND dogovor_name