Oracle 为所有重复记录创建相同组id的查询
我有oracle表包含如下字段Oracle 为所有重复记录创建相同组id的查询,oracle,plsql,Oracle,Plsql,我有oracle表包含如下字段 rowindx,mdnnumber,poivalue,groupid 我想通过poivalue将相同的groupid分配给所有重复的记录 我为此创建了函数,但我想知道是否可以使用sql查询?如何使用?假设我可以使用POI值作为组ID Update table set GROUPID=PoiValue where POIValue in ( Select POIValue from table group by poivalue havin
rowindx,mdnnumber,poivalue,groupid
我想通过poivalue
将相同的groupid分配给所有重复的记录
我为此创建了函数,但我想知道是否可以使用sql查询?如何使用?假设我可以使用POI值作为组ID
Update table set GROUPID=PoiValue
where POIValue in (
Select POIValue
from table
group by poivalue
having count(poivalue) > 1)
假设我可以使用POI值作为组ID,请确定
Update table set GROUPID=PoiValue
where POIValue in (
Select POIValue
from table
group by poivalue
having count(poivalue) > 1)
这将生成groupid为1,2,3
update t
set groupid =
(select groupid
from (select poivalue, ROWNUM groupid
from (select distinct poivalue from t order by poivalue) t2) t2
where t2.poivalue = t.poivalue)
这将生成groupid为1,2,3
update t
set groupid =
(select groupid
from (select poivalue, ROWNUM groupid
from (select distinct poivalue from t order by poivalue) t2) t2
where t2.poivalue = t.poivalue)
您如何知道要使用哪个groupid?例如,如果poivalue=1的一行的groupid=10,而poivalue=1但groupid=11的另一行,则应更新哪一行?您如何知道使用哪一个groupid?例如,如果poivalue=1的一行的groupid=10,而poivalue=1但groupid=11的另一行,应更新哪一行?