gpt4 book ai didi

php - 使用 MySQL 查询进行半复杂的数学运算

转载 作者:行者123 更新时间:2023-11-29 18:46:14 27 4
gpt4 key购买 nike

我不确定如何将代码导入到 stackoverflow 中,使其看起来像表格,因此我将导入下面的 2 张照片。

这些是我需要在查询中使用的表的屏幕截图。我想将竞赛“experts_cooperatives”与用户cocodition_x 和_y 进行比较,看看谁最接近,从而获胜。

我不知道如何用 SQL 编写它,但这是我的想法:

//Loop through all the results and do as follow

$user_xy = coordinate_x + coordinate_y;
$expert_xy = explode(',', 'experts_coordinates');
$winning_coords = $expert_xy[0] + $expert_xy[1];
$results = $user_xy - $winning_coords;

//Loop again too see who was the closest too '0'.
//Winner will be the users closest too 0.

类似这样的吗?

NOTE! This is intended to run server side once a week.

Users table with coordinates

Competition table with winning coordinates

PS:php标签是因为我使用了一些php代码示例来尝试和演示我的想法。

最佳答案

要查找具有 xy 坐标的最近节点,使用欧几里德距离可能会很有用:

function euclidDistanceSquared (a, b) {
return (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]);
}

$user_xy = array(coordinate_x, coordinate_y);
$expert_xy = explode(',', 'experts_coordinates');
$dsquared = euclidDistanceSquared($user_xy, $expert_xy);

//find smallest dsquared using a loop

关于php - 使用 MySQL 查询进行半复杂的数学运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44624863/

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