0

I am using mysql to count the number of point features (shops) within a polygon feature (postsec).

The select query I have works fine, but I want to update table postsec with the generated results. The query I have is below:

select pc_sec, count(*) as count from shops 
join postsec on st_within(shops.SHAPE,postsec.SHAPE) 
where shops.shop_cat > 0 and shop_cat < 10 group by pc_sec

I have tried a number of methods for doing this e.g. update postsec set new_column = ([select query]) but can't seem to find the right way.

Stev_k
  • 2,118
  • 3
  • 22
  • 36

1 Answers1

1

Something like this should work

update postsec 
inner join 
(
   select pc_sec, count(*) as pseccount 
   from shops 
   join postsec on st_within(shops.SHAPE,postsec.SHAPE) 
   where shops.shop_cat between 1 and 9
   group by pc_sec
) x on x.pc_sec = postsec.id
set count_column = x.pseccount 
juergen d
  • 201,996
  • 37
  • 293
  • 362