Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以根据计数更新表中的列?假设表中有2条相似的记录,根据where子句返回2条记录。但是如何限制更新语句只有在count为1时才更新记录,否则不更新。有可能这样做吗?
问候,
拉吉
UPDATE table SET column = x WHERE (SELECT COUNT(x) FROM x = 1)
为此,您可以在 where 子句中使用嵌套查询,该查询将返回记录计数,您可以检查它是 0 还是 1。
所以它会是这样的:
UPDATE table SET colName = x WHERE (SELECT COUNT(*) FROM table group by colName having colName =x) < =1;