Closed. This question needs details or clarity . It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post .
Closed 2 days ago.
Improve this question
i am try to do aggregate Function with 3 tables. and when i am using in sum on on of the table is not working
select
t1.EmployeeName,sum(t2.Amount), t2.DateOfTransaction, t3.Department
from
tblEmployee2 t1
right join
tblTransaction t2 on t1.EmployeeNumber = t2.EmployeeNumber
join
tblDepartment t3 on t1.EmployeeName = t3.DepartmentHead
group by t2.EmployeeNumber
problem get
Msg 8120, Level 16, State 1, Line 3
Column 'tblEmployee2.EmployeeName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
1条答案
按热度按时间wnrlj8wa1#
When you use the group by, the field in the select must be in the group by or aggregate
you have to use max with group by or write a window function
group by (use max)
Window function