如何在sql中获得percantage

如何在sql中获得percantage

本文介绍了如何在sql中获得percantage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在获取百分比时遇到问题。



这是我的查询



Hi,
I have a problem with getting the percentage.

this is my query

 select cid,RecommendToFriend from companyreviews where isrss=0 and cid=98
result is

cid    RecommendToFriend 
98      1
98      1
98      0
98      0
98      1

I want the percentage of Recommendtofriend field.

I have to write like this




select ( sum(RecommendToFriend) /(select Count(RecommendToFriend) from CompanyReviews where IsRss=0 and cid=98))* 100  from companyreviews where IsRss=0 and cid=98





我没有得到回答。



请帮帮我。



谢谢......



I am not getting the answere.

Please help me.

Thank you......

推荐答案

select sum(RecommendToFriend)*100.0/count(RecommendToFriend) from CompanyReviews where IsRss=0 and cid=98


SELECT cast(SUM(RecommendToFriend) AS decimal(10,2)) / COUNT(RecommendToFriend)*100
FROM companyreviews


这篇关于如何在sql中获得percantage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 21:51