我有一个pdo查询来搜索NE SW square / grid中的位置,它似乎返回了不符合条件的杂散结果。
$query ="SELECT id, COUNT(id) as records, geohash, lat, lng FROM places";
$query .=" WHERE
(:latMax < :latMin AND lat BETWEEN :latMax AND :latMin) || (:latMax > :latMin AND lat BETWEEN :latMin AND :latMax )
AND
(:lonMin < :lonMax AND lng BETWEEN :lonMin AND :lonMax) || ( :lonMin > :lonMax AND lng BETWEEN :lonMax AND :lonMin)";
$query .= " Group By geohash";
$stmt = $db->prepare($query);
$stmt->bindParam(':latMin', $latMin);
$stmt->bindParam(':latMax', $latMax);
$stmt->bindParam(':lonMin', $lonMin);
$stmt->bindParam(':lonMax', $lonMax);
$result = array();
if ($stmt->execute()) {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$result[] = $row;
}
}
例如
$latMax =43.8573636288909;
$latMin = 43.360191211239965;
$lonMax = -78.53449632050786;
$lonMin =-80.81827927949223;
它会返回正确的resutlt加上一些杂散结果,在这个例子中它返回一个lat的位置:55.871751500000和lng:-4.288359800000
哪个应该超出where语句的范围?
他们为什么会发生这种情况有明显的原因?