mysql - 在 Mysql 中使用 Haversine 计算时无法使 COUNT() 工作

标签 mysql

我已经让Haversine 可以检索满足距离条件的行,但无法让Mysql COUNT() 函数工作。这是我的代码的一部分:

$query1 = "
SELECT COUNT(\"$table.*\") AS numrows1, outcodepostcodes.lat, outcodepostcodes.lng
,111.045* DEGREES(ACOS(COS(RADIANS($latpoint))
             * COS(RADIANS(outcodepostcodes.lat))
             * COS(RADIANS($longpoint) - RADIANS(outcodepostcodes.lng))
            + SIN(RADIANS($latpoint))
             * SIN(RADIANS(outcodepostcodes.lat)))) AS distance
FROM $table
LEFT JOIN outcodepostcodes
ON UPPER(\"$table.postcode\")=outcodepostcodes.outcode
HAVING ROUND(distance,2) <= $choosedistn
ORDER BY rent $reihenach LIMIT $offset, $rowsPerPage
";

然后按如下方式处理 $queries:

$result1  = mysql_query($query1) or die('Error, query1 failed:' .mysql_error());
$result2  = mysql_query($query2) or die('Error, query2 failed:' .mysql_error());
$row1     = mysql_fetch_array($result1, MYSQL_ASSOC);
$row2     = mysql_fetch_array($result2, MYSQL_ASSOC);
$numrows1 = $row1['numrows1'];
$numrows2 = $row2['numrows2'];  

我得到的 $numrows 为 NULL。非常感谢任何帮助。

最佳答案

这里的引号是错误的COUNT(\"$table.*\") AS numrows1

就这样吧

COUNT(`$table`.*) AS numrows1

关于mysql - 在 Mysql 中使用 Haversine 计算时无法使 COUNT() 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38556166/

相关文章:

java - 插入记录时在 JDBC Java 中出错

mysql - 如何为 MySQL 查询中的所有记录生成唯一的 UUID?

mysql - 更新多行的列

mysql - Laravel/十月 : multidimensional array mysql

php - 如何使 Zip Blob 文件准备好从 MySQL 数据库下载

PHP 和 MySQL - 哪种变量类型最适合该数组?

mysql - mysql数据库建表困难

php - 有没有更智能的方法来使用 PHP 和 MySQL 加载多对多关系?

mysql - 将 mysql sql 转换为 sql server

mySQL "select"通过 JDBC 区分大小写,但通过命令行不区分大小写