我想计算数据库中每一行的total_votes百分比.我正在使用sql server 2008 [英] I want to calculate the percentage of the total_votes for each row in the database.I am using sql server 2008

查看:237
本文介绍了我想计算数据库中每一行的total_votes百分比.我正在使用sql server 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想计算数据库中每一行中每个total_votes的百分比.下面的存储过程将更新该特定候选人的total_votes并将其增加1.我在Sql Server 2008中的代码如下所示

Hello,I want to calculate the percentage of each total_votes in each row in the database. The stored procedure below updates the total_votes for that particular candidate and increments it by 1.My code in Sql server 2008 looks as follows

ALTER proc [dbo].[update_total]
(@candidate_id int
)
as
update  Votes
set total_votes=total_votes+1
where candidate_id=@candidate_id 

推荐答案

尝试
select total_votes * 100 / (select sum(total_votes) from Votes) from Votes where candidate_id=@candidate_id

.


这篇关于我想计算数据库中每一行的total_votes百分比.我正在使用sql server 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆