Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: list of points to rectangle

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>

?

like image 969
noamtm Avatar asked Aug 01 '10 11:08

noamtm


1 Answers

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.
like image 56
Will A Avatar answered Sep 24 '22 06:09

Will A