一、powerI()--https://www.w3schools.com/mysql/func_mysql_power.asp
The POWER() function returns the value of a number raised to the power of another number.
Note: This function is equal to the POW() function.
语法:
POWER(x, y)
x | Required. A number (the base) |
y | Required. A number (the exponent) |
二、sqrt--https://www.w3schools.com/mysql/func_mysql_sqrt.asp
Definition and Usage
The SQRT() function returns the square(平方) root of a number.
Syntax
SQRT(number)
Parameter Values
Parameter | Description |
---|---|
number | Required. A number to calculate the square root of. Must be greater than 0 |
例:
表 point_2d 保存了所有点(多于 2 个点)的坐标 (x,y) ,这些点在平面上两两不重合。
写一个查询语句找到两点之间的最近距离,保留 2 位小数。
| x | y |
|----|----|
| -1 | -1 |
| 0 | 0 |
| -1 | -2 |
最近距离在点 (-1,-1) 和(-1,2) 之间,距离为 1.00 。所以输出应该为:
| shortest |
|----------|
| 1.00 |
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/shortest-distance-in-a-plane
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
select round(min(sqrt(power((p1.x-p2.x),2)+power((p1.y-p2.y),2))),2) as shortest
from point_2d p1
join point_2d p2
where (p1.x,p1.y)<>(p2.x,p2.y)