SELECT id,login,contact_number, store_id, COUNT(contact_number) AS COUNT
FROM USER
WHERE store_id = 1
AND is_number_verified = 1
GROUP BY contact_number
HAVING COUNT(contact_number) > 1
现在我想将number_verified的所有值更新为0并希望保留 为每个用户验证了1行。我试过这个但是没有工作
UPDATE `user` SET is_number_verified = 0
WHERE id IN
(
SELECT id
FROM USER where store_id = 1
AND is_number_verified = 1
GROUP BY contact_number
HAVING COUNT(contact_number) > 1
)
答案 0 :(得分:0)
您可以尝试使用另一个内部查询,例如:
UPDATE `user` SET is_number_verified = 0
WHERE id IN
(SELECT temp.id FROM (
SELECT id,login,contact_number, store_id, COUNT(contact_number) AS COUNT
FROM USER
WHERE store_id = 1 AND is_number_verified = 1
GROUP BY contact_number
HAVING COUNT(contact_number) > 1) AS temp)