sql – 从另一个表的行批量更新表

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
    )

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...