本文介绍了寻找最近的边(多边形)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为所有sql粉丝设置了一个谜题。


想象一个有12个边的多边形(SideA,SideB,SideC等)


在这个多边形内有96个点(Pt1,Pt2,Pt3等)。


现在让我说我有一个表,每个点到每一边的距离
距离

Pt1 SideA 25.6683

Pt1 SideB 37.6778

Pt1 SideC 576.8383

Pt2 SideA 352.2652

Pt2 SideB 3.8953

Pt2 SideC 46.9563






我需要做的是,对于每个点,找到最近的两个边。所以我需要对点名进行排序,找到该点的距离中的两个最小值,并报告一侧。


我该怎么做?我们很难用正确的语法包裹我们的大脑。


感谢您的帮助!

I have a puzzle for all you sql fans.

Imagine a polygon with 12 sides (SideA, SideB, SideC, etc)

Within this polygon are 96 points (Pt1, Pt2, Pt3, etc).

Now let''s say I have a table that has the distances from each point to each side
Point Side Distance
Pt1 SideA 25.6683
Pt1 SideB 37.6778
Pt1 SideC 576.8383
Pt2 SideA 352.2652
Pt2 SideB 3.8953
Pt2 SideC 46.9563


etc.

What I need to do is, for each point, find the two closest sides. So I need to sort on point name, find the two minimum values in Distance for that point, and report the side.

How do I do this? We are having a hard time wrapping our brains around the correct syntax.

Thanks for any help!

推荐答案



我不认为导出基于代码的解决方案会有什么问题,但SQL是我的弱点。我想象它必须涉及一个子查询,类似于:

I don''t think that it would be much of a problem to derive a code based solution, but SQL is my weakness. I''m imagine that it would have to involve a Sub-Query, something along the lines of:

展开 | 选择 | Wrap | 行号


展开 | 选择 | Wrap | 行号



这篇关于寻找最近的边(多边形)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 00:56