SQL:点列表转矩形

5

我有两个表:

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

假设每个区域恰好有4个点,并且这些点描述了一个矩形-是否有一条SQL查询语句可以帮助我得到这个视图:

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

?

1个回答

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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接