具有计数的SQL UPDATE

时间:2018-10-24 09:53:37

标签: sql oracle group-by sql-update having

我有这张桌子

A B
1 1H
2 1H
1 1G
1 1E

我需要更新此表的列A,该列将max(a)分组为B,其count(*)=2。

结果将如下所示:

A B
2 1H
2 1H
1 1G
1 1E

2 个答案:

答案 0 :(得分:0)

也许吗?

update tablename t1
set A = (select max(A) from tablename t2 where t2.B = t1.B)
where B in (select B from tablename group by B having count(*) >= 2)

答案 1 :(得分:0)

您可以在下面尝试

app:layout_constrainedHeight="true"