mysql-power()求次方,sqrt()开根号

本文介绍了MySQL中的数学函数power()和sqrt()。power()函数用于求一个数的另一个数次方,等同于POW()函数;sqrt()函数则返回一个数的平方根。详细语法及参数值见文章。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、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)
xRequired. A number (the base)
yRequired. 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

ParameterDescription
numberRequired. 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)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值