TransWikia.com

Run ST_DWithin on a subquery result from a different table

Geographic Information Systems Asked by Roy Arturo on March 24, 2021

I have two tables "Customers", and "Providers" in my PostgreSQL DB. They both have a ‘geom’ column. Now, customer Table has a column called e.g. "profession".

I want to get the COUNT of providers from "Providers" table within 1000m from all the customers in the "Customers" table, where e.g. "profession" = "GIS Developer"

Even better, I’d like to have a function called e.g. _getCustomersStats(profession)

So I can call it like this: SELECT * FROM public._getCustomersStats(‘GIS Developer’)

and get this result:

customer_count providers_within_1000m
30000 400000

I’ve tried this query bellow. I haven’t gotten to creating the function yet because this query is not working for me:


with
    cust as (
    select
        *
    from
        Customers as c
    where
        c.profession = 'GIS Developer'
    ),
select
    count(*)
from
    cust, Providers as p
where
    ST_DWithin (cust.geom, p.geom, 1000)

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP