如何使用具有&和" ORDER BY&"sql中的子句 [英] How to use" HAVING "and "ORDER BY" clause in sql
本文介绍了如何使用具有&和" ORDER BY&"sql中的子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下所示的sql查询,sql服务器说他们是HAVING和ORDER中的错误by是他们在HAVING和ORDER BY附近语法方面的任何错误,任何人都可以帮忙.
I have sql query like shown below the sql server says that their is error in HAVING and ORDER bY is their any error with syntax near HAVING and ORDER BY, can anyone help.
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 ;
推荐答案
在此处使用 where
而不是 having
.
具有
对于缩小汇总值的条件很有用. where
对于缩小未聚合数据的条件很有用.
having
is useful for narrowing conditions on aggregate values.
where
is useful for narrowing conditions on un-aggregated data.
更新
SQL Server不是MySQL,可以在一个服务器上运行...
Update
SQL Server is not MySQL, what works on one ...
- 可以恰好在另一端工作
- 可能需要稍微调整一下工作
- 可能需要完全重新设计后才能生效.
这应该是您所需要的
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 ) ) ) ;
这篇关于如何使用具有&和" ORDER BY&"sql中的子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文