Guest User

Untitled

a guest
Dec 13th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. SELECT COUNT(*) as customer_count FROM customer_table c
  2. WHERE EXISTS(
  3. SELECT 1 FROM locations_table s
  4. WHERE ST_Distance_Sphere(s.the_geom, c.the_geom) < 10000
  5. )
  6.  
  7. create table customer (
  8. loc real,
  9. name text
  10. );
  11. create index on customer(loc);
  12. create table location (
  13. loc real,
  14. name text
  15. );
  16. create index on location(loc);
  17. insert into customer values (1,'c1'), (2,'c2');
  18. insert into location values (1.1, 'l1'), (1.2, 'l2');
  19. select cat, count(*) from (
  20. select bussiness, "name", dist ,
  21. case when dist>.5 then 'far'
  22. when dist > .11 then 'nearby'
  23. else 'local' end cat
  24. from (
  25. select l.name bussiness, c.name "name", abs(l.loc - c.loc) dist -- Use your ST_Distance_Sphere
  26. from location l, customer c
  27. where abs(l.loc - c.loc)< .89 -- ST_DWithin is here
  28. ) foo
  29. ) bar
  30. group by cat
  31.  
  32. CREATE OR REPLACE VIEW b1 as
  33. SELECT ST_Buffer(the_geom,10000) as geom, store_name, fid
  34. FROM stores;
  35.  
  36. CREATE OR REPLACE VIEW r2 as
  37. SELECT ff.fid, ff.store_name, ST_Difference(ff.the_geom, g.the_geom) as new_geom
  38. FROM b2 ff
  39. JOIN b1 g ON (g.fid= ff.fid)
  40. GROUP BY ff.fid, ff.store_name, g.the_geom, ff.the_geom;
Add Comment
Please, Sign In to add comment