![](/img/trans.png)
[英]Update a column of a table with the count of other column in the same table in a MySQL server
[英]count one column and update another in same table in mysql
我想基於同一表中另一列的計數來更新一列。 我嘗試下面的查詢,但沒有運氣。
update
table
set conntype='Multiple'
where (select COUNT(cpemac) as nos from table group by cpemac) > 1
我收到以下錯誤:
在MySQL中,您需要使用JOIN
:
update t join
(select cpemac, count(cpemac) as nos
from t
group by cpemac
) tt
on t.cpemac = tt.cpemac
set t.conntype = 'Multiple'
where cnt > 1;
這是MySQL的特定限制。
但是,我應該指出,您的版本無法在任何數據庫中使用。 根據子查詢的結果,它將更新所有行或不更新任何行。 子查詢和外部查詢之間沒有連接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.