mah*_*esh 2 c# mysql asp.net sql-server-2005
我有sql查询,如下面显示的sql服务器说他们是HAVING错误和ORDER BY是他们的任何错误与语法附近HAVING和ORDER BY,任何人都可以帮助.
SELECT Id,
Name1,
ZipCode,
StreetName,
StreetNumber,
State1,
Lat,
Lng,
Keyword,
( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS( (Lat/57.2958) ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN( Lat/57.2958 ) ) ) AS distance
FROM Business_Details
HAVING (distance < 1.5) and (Keyword like '%plumber%')
ORDER BY distance ;
Run Code Online (Sandbox Code Playgroud)
where在这里使用而不是having.
having有助于缩小总值的条件.
where对于缩小未聚合数据的条件非常有用.
更新
SQL Server不是MySQL,什么适用于...
这应该是你需要的
SELECT Id,
Name1,
ZipCode,
StreetName,
StreetNumber,
State1,
Lat,
Lng,
Keyword,
( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS( (Lat/57.2958) ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN( Lat/57.2958 ) ) ) AS distance
FROM Business_Details
where (Keyword like '%plumber%')
and ( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS( (Lat/57.2958) ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN( Lat/57.2958 ) ) ) < 1.5
ORDER BY ( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS( (Lat/57.2958) ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN( Lat/57.2958 ) ) ) ;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10484 次 |
| 最近记录: |