请有人给我正确的语法。
MySQL UPDATE tblcontact SET MainContact = 1
WHERE COUNT(tblcontact.CompanyID) = 1
GROUP BY tblcontact.CompanyID
答案 0 :(得分:0)
我明白了。您希望将字段设置为1,其中只有一条记录。试试这个:
UPDATE tblcontact c join
(select CompanyID, count(CompanyID) as cnt
from tblcontact
group by CompanyId
) cc
on c.CompanyId = cc.CompanyId and cnt = 1
SET c.MainContact = 1 ;