我不知道为什么会一直回来:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM vendas LEFT JOIN clientes c ON c.id = vendas.idCliente AND c.idRespons' at line 2
Mysql查询:
UPDATE vendas
FROM vendas
LEFT JOIN clientes c ON c.id = vendas.idCliente AND c.idResponsavel IS NOT NULL
LEFT JOIN funcionarios f ON f.id = c.idResponsavel
SET vendas.idVendedorResponsavel = f.id
WHERE vendas.idVendedorAtendente is NULL
答案 0 :(得分:0)
试试这个
UPDATE vendas v
LEFT JOIN clientes c
ON c.id = v.idCliente
AND c.idResponsavel IS NOT NULL
LEFT JOIN funcionarios f
ON f.id = c.idResponsavel
SET v.idVendedorResponsavel = f.id
WHERE v.idVendedorAtendente is NULL
答案 1 :(得分:0)
你可以像这样离开FROM vandas条款
UPDATE vendas v
LEFT JOIN clientes c ON c.id = v.idCliente AND c.idResponsavel IS NOT NULL
LEFT JOIN funcionarios f ON f.id = c.idResponsavel
SET v.idVendedorResponsavel = f.id
WHERE v.idVendedorAtendente is NULL
答案 2 :(得分:0)
您无法在UPDATE规范中所述的MySQL Update Query中设置这样的from子句: http://dev.mysql.com/doc/refman/5.0/en/update.html
我相信你想要的是这样的:
UPDATE vendas LEFT JOIN clientes c ON c.id = vendas.idCliente AND c.idResponsavel IS NOT NULL
LEFT JOIN funcionarios f ON f.id = c.idResponsavel
SET vendas.idVendedorResponsavel = f.id
WHERE vendas.idVendedorAtendente is NULL