2桌:
Employees - EmployeeID - LeadCount Leads - leadID - employeeID
我想通过计算Leads表中具有相同EmployeeID的潜在客户数来更新Employees.LeadCount列.
注意:可能有多个具有相同employeeID的潜在客户,因此我必须执行DISTINCT(SUM(employeeID)).
解决方法
UPDATE Employees E SET E.LeadCount = ( SELECT COUNT(L.EmployeeID) FROM Leads L WHERE L.EmployeeID = E.EmployeeID )