删除具有相同列值的行
我正在从邮政编码表中查询一堆城市。我只想通过独特的“城市”获取结果。 (很多城市都有多个邮政编码。)这怎么办?
$query = sprintf("SELECT `Zip`, `City`, `State`, `Lat`, `Long`,
( 3959 * acos( cos( radians('%s') ) * cos( radians( `Lat` ) ) *
cos( radians( `Long` ) - radians('%s') ) +
sin( radians('%s') ) * sin( radians( `Lat` ) ) ) ) AS distance
FROM Zips HAVING distance < '%s' ORDER BY distance LIMIT 0 , 18",
mysql_real_escape_string($lat),
mysql_real_escape_string($lng),
mysql_real_escape_string($lat),
mysql_real_escape_string($radius));
$result = mysql_query($query, $dbConn);
I'm querying a bunch of cities from a zip-code table. I'd only like to grab results with an unique 'City'. (Lots of cities have multiple zips.) How could this be done?
$query = sprintf("SELECT `Zip`, `City`, `State`, `Lat`, `Long`,
( 3959 * acos( cos( radians('%s') ) * cos( radians( `Lat` ) ) *
cos( radians( `Long` ) - radians('%s') ) +
sin( radians('%s') ) * sin( radians( `Lat` ) ) ) ) AS distance
FROM Zips HAVING distance < '%s' ORDER BY distance LIMIT 0 , 18",
mysql_real_escape_string($lat),
mysql_real_escape_string($lng),
mysql_real_escape_string($lat),
mysql_real_escape_string($radius));
$result = mysql_query($query, $dbConn);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在错误的地方使用了
HAVING
,这里需要WHERE
,并使用GROUP BY
按城市对结果进行分组编辑
您也可以尝试
或
You are using
HAVING
at a wrong placeWHERE
is needed here and useGROUP BY
to group result by cityEDIT
You could also try
OR
尝试使用
OR
try with
OR