我有两个带有以下字段的表
emp_table: emp_id, emp_name
salary_increase: emp_id, inc_date, inc_amount
我需要编写一个查询,其中提供员工详细信息、员工加薪的次数、最大加薪金额以及加薪日期。这是我到目前为止所拥有的:
SELECT e.*, count(i.inc_amount), max(i.inc_amount)
FROM salary_increase AS i
RIGHT JOIN emp_table AS e
ON i.emp_id=e.emp_id
GROUP BY e.emp_id;
这正确地给出了除授予最大增幅的日期之外的所有要求。我尝试了以下方法但没有成功:
SELECT e.*, count(i.inc_amount), max(inc_amount), t.inc_date
FROM salary_increase AS i
RIGHT JOIN emp_table AS e
ON i.emp_id=e.emp_id
RIGHT JOIN
(
SELECT emp_id, inc_date FROM salary_increase
WHERE inc_amount=max(inc_amount) GROUP BY emp_id
) AS t
ON e.emp_id=t.emp_id
GROUP BY e.emp_id;
这会出现错误“组函数的使用无效”。有谁知道我做错了什么?