Guest User

Untitled

a guest
Apr 24th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.15 KB | None | 0 0
  1. REPLACE INTO areahierarki (area,withinArea,dealer,size)
  2. SELECT
  3. areas1.id as id,
  4. areas2.id as withinId,
  5. res.dealer,
  6. v_size as size
  7. FROM
  8.     (SELECT viewable.dealer, Area(Envelope(viewable.poly)) as v_size, Area(Envelope(withinPolys.poly)) as w_size, viewable.area as area1, withinPolys.area as area2 FROM
  9.         (
  10.             SELECT areapolys.*,
  11.                 areas.dealer
  12.             FROM main.areapolys
  13.             JOIN areas ON areapolys.area = areas.id
  14.         ) as viewable
  15.         LEFT JOIN areapolys withinPolys ON withinPolys.area != viewable.area
  16.            
  17.         AND
  18.           (
  19.               (
  20.                   Within(viewable.anchor,withinPolys.poly)
  21.                   #The containg area should be SIGNIFICANTLY larger to be considered
  22.                   AND Area(Envelope(viewable.poly))*10 < Area(Envelope(withinPolys.poly))
  23.               )
  24.               OR
  25.               (
  26.                    Within(viewable.poly,withinPolys.poly)
  27.               )
  28.           )
  29.     ) as res
  30. JOIN areas areas1 ON areas1.id = area1
  31. LEFT JOIN areas areas2 ON areas2.id = area2
  32. WHERE areas1.id = 9
  33. ORDER BY areas2.id IS NOT NULL DESC, w_size ASC
Advertisement
Add Comment
Please, Sign In to add comment