update gis_net_geo_cln_line
set street_unique_code = x.street_uniq_code from (Select distinct m.line_code,
m.street_uniq_code,
r.min_uzaklik
from (Select x.line_code,
y.street_uniq_code,
ST_Distance(x.boru_geom,
y.yol_geom) as uzaklik
from (select t.line_code,
r.region_id,
t."SP_GEOMETRY" as boru_geom
from gis_net_geo_cln_line t,
gis_adr_geo_region r
where t.street_unique_code <= 0
and r.region_level = 3
and ST_Intersects(t."SP_GEOMETRY",
r."SP_GEOMETRY") = TRUE) x,
(select t."SP_GEOMETRY" as yol_geom,
ms.region_id as mahalle_id,
ms.street_uniq_code
from gis_adr_geo_street t,
gis_adr_lt_region_street ms
where t.common_street_code =
ms.common_street_code) y
where ST_DWithin(x.boru_geom,
y.yol_geom,
50000)) m
inner join (Select o.line_code,
MIN(o.uzaklik) as min_uzaklik
from (Select x.line_code,
y.street_uniq_code,
ST_Distance(x.boru_geom,
y.yol_geom) as uzaklik
from (select t.line_code,
r.region_id,
t."SP_GEOMETRY" as boru_geom
from gis_net_geo_cln_line t,
gis_adr_geo_region r
where t.street_unique_code <= 0
and r.region_level = 3
and ST_Intersects(t."SP_GEOMETRY",
r."SP_GEOMETRY") = TRUE) x,
(select t."SP_GEOMETRY" as yol_geom,
ms.region_id as mahalle_id,
ms.street_uniq_code
from gis_adr_geo_street t,
gis_adr_lt_region_street ms
where t.common_street_code =
ms.common_street_code) y
where ST_DWithin(x.boru_geom,
y.yol_geom,
50000)) o
group by o.line_code) r
on m.line_code =
r.line_code
and m.uzaklik =
r.min_uzaklik
order by m.line_code) x
where gis_net_geo_cln_line.line_code = x.line_code
and gis_net_geo_cln_line.street_unique_code <= 0