本文介绍了如何使用" HAVING"和" ORDER BY"在SQL子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有SQL查询像所示的SQL Server的下面说,他们当中也没有错误和ORDER BY是他们与语法的错误附近HAVING和ORDER BY,谁能帮助。
SELECT标识,
名1,
邮编code,
街道名称,
街牌号码,
状态1,
纬度,
液化天然气,
关键词,
(6371 * ACOS(COS((12.925432 / 57.2958))* COS((纬度/ 57.2958))* COS((LNG / 57.2958) - (77.5940171 / 57.2958))+ SIN(12.925432 / 57.2958)* SIN(纬度/ 57.2958 )))AS距离
从Business_Details
HAVING(距离< 1.5)和(关键字LIKE'%管道工%')
ORDER BY距离;
解决方案
使用,其中
在这里,而不是有
。
有
是在聚合值缩小条件是有用的。结果其中,
是缩小在未汇总的数据病症。
更新结果
SQL Server是不是MySQL的,在一个什么工作......
- 五月的只是的另一 工作
- 可能需要稍微调整,以
工作 - 可能需要完全
重新enginerred前,将正常工作。
这应该是你所需要的。
SELECT标识,
名1,
邮编code,
街道名称,
街牌号码,
状态1,
纬度,
液化天然气,
关键词,
(6371 * ACOS(COS((12.925432 / 57.2958))* COS((纬度/ 57.2958))* COS((LNG / 57.2958) - (77.5940171 / 57.2958))+ SIN(12.925432 / 57.2958)* SIN(纬度/ 57.2958 )))AS距离
从Business_Details
其中(关键字LIKE'%管道工%')
和(6371 * ACOS(COS((12.925432 / 57.2958))* COS((纬度/ 57.2958))* COS((LNG / 57.2958) - (77.5940171 / 57.2958))+ SIN(12.925432 / 57.2958)* SIN(纬度/ 57.2958)))≤; 1.5
ORDER BY(6371 * ACOS(COS((12.925432 / 57.2958))* COS((纬度/ 57.2958))* COS((LNG / 57.2958) - (77.5940171 / 57.2958))+ SIN(12.925432 / 57.2958)* SIN(纬度/57.2958)));
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 ;
解决方案
Use where
here instead of having
.
having
is useful for narrowing conditions on aggregate values.where
is useful for narrowing conditions on un-aggregated data.
Update
SQL Server is not MySQL, what works on one ...
- May just work on the other
- May need to be tweaked slightly towork
- May need to be completelyre-enginerred before it will work.
This should be what you need
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 ) ) ) ;
这篇关于如何使用&QUOT; HAVING&QUOT;和&QUOT; ORDER BY&QUOT;在SQL子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!