Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 为所有重复记录创建相同组id的查询_Oracle_Plsql - Fatal编程技术网

Oracle 为所有重复记录创建相同组id的查询

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

我有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 
  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的另一行,应更新哪一行?