gpt4 book ai didi

database - MariaDB 中不存在 FUNCTION ST_Distance_Sphere

转载 作者:搜寻专家 更新时间:2023-10-30 19:47:33 25 4
gpt4 key购买 nike

我想获取我所在位置周围的所有位置,但函数 ST_Distance_Sphere 不起作用。

我的查询:

select *, astext(location) as location from `locations`
where ST_Distance_Sphere(location, POINT(35.905069591297, 49.765869174153)) < 1000

错误:

SQLSTATE[42000]: Syntax error or access violation:
1305 FUNCTION app.ST_Distance_Sphere does not exist (SQL:
select *, astext(location) as location from `locations`
where ST_Distance_Sphere(location, POINT(35.905069591297, 49.765869174153)) < 1000)

最佳答案

如果还需要MariaDB中的函数,可以根据公式创建函数

    CREATE FUNCTION `st_distance_sphere`(`pt1` POINT, `pt2` POINT) RETURNS 
decimal(10,2)
BEGIN
return 6371000 * 2 * ASIN(SQRT(
POWER(SIN((ST_Y(pt2) - ST_Y(pt1)) * pi()/180 / 2),
2) + COS(ST_Y(pt1) * pi()/180 ) * COS(ST_Y(pt2) *
pi()/180) * POWER(SIN((ST_X(pt2) - ST_X(pt1)) *
pi()/180 / 2), 2) ));
END

关于database - MariaDB 中不存在 FUNCTION ST_Distance_Sphere,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44409012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com