Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT COUNT(*) as customer_count FROM customer_table c
- WHERE EXISTS(
- SELECT 1 FROM locations_table s
- WHERE ST_Distance_Sphere(s.the_geom, c.the_geom) < 10000
- )
- create table customer (
- loc real,
- name text
- );
- create index on customer(loc);
- create table location (
- loc real,
- name text
- );
- create index on location(loc);
- insert into customer values (1,'c1'), (2,'c2');
- insert into location values (1.1, 'l1'), (1.2, 'l2');
- select cat, count(*) from (
- select bussiness, "name", dist ,
- case when dist>.5 then 'far'
- when dist > .11 then 'nearby'
- else 'local' end cat
- from (
- select l.name bussiness, c.name "name", abs(l.loc - c.loc) dist -- Use your ST_Distance_Sphere
- from location l, customer c
- where abs(l.loc - c.loc)< .89 -- ST_DWithin is here
- ) foo
- ) bar
- group by cat
- CREATE OR REPLACE VIEW b1 as
- SELECT ST_Buffer(the_geom,10000) as geom, store_name, fid
- FROM stores;
- CREATE OR REPLACE VIEW r2 as
- SELECT ff.fid, ff.store_name, ST_Difference(ff.the_geom, g.the_geom) as new_geom
- FROM b2 ff
- JOIN b1 g ON (g.fid= ff.fid)
- GROUP BY ff.fid, ff.store_name, g.the_geom, ff.the_geom;
Add Comment
Please, Sign In to add comment