0

我有一张表,上面有点XY。我需要找到最接近原点的Xand点。Y(0, 0)

我正在尝试这种方式:

SELECT *
FROM `line` 
WHERE xi < yi and 0 < xi and 0 < yi and yi < xi
ORDER BY yi and xi  ASC 
Limit 100

但我没有得到想要的值。

4

3 回答 3

6

到原点的距离由 给出sqrt(xi^2 +yi^2)。由于平方根是严格升序的,您可以省略它以进行排序。这给出了:

SELECT *
FROM `line` 
ORDER BY xi*xi + yi*yi
Limit 100
于 2013-06-02T17:05:20.757 回答
1

您需要计算距离d = sqrt(x²+y²)以获取距原点最近的点

select x, y, sqrt(x*x + y*y) as distance
from `line` 
order by distance asc
limit 1
于 2013-06-02T17:05:14.023 回答
1
SELECT xi, yi, xi * xi + yi * yi As r2
FROM line
ORDER BY r2
于 2013-06-02T17:06:23.733 回答