5

I have two tables:

regions <id>
points <region_id, x, y>

Assuming there are exactly 4 points per region, and these points describe a rectangle -- is there an SQL query that will bring me this view:

rectangular_regions <region_id, x1, y1, x2, y2>

?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
noamtm
  • 12,435
  • 15
  • 71
  • 107

1 Answers1

10
SELECT region_id, MIN(x) AS x1, MIN(y) AS y1, MAX(x) AS x2, MAX(y) AS y2 
FROM points 
GROUP BY region_id.
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Will A
  • 24,780
  • 5
  • 50
  • 61