如何将sql server中的列值相加 [英] how sum the column values in sql server

查看:826
本文介绍了如何将sql server中的列值相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facid Feedbackid FacQ1 FacQ2

1 1 5 4

2 1 4 3

3 1 4 2

1 2 5 4

2 2 4 2

3 2 4 3



总计26 18



i想要总和Facq1,FacQ2并除以行数。



我想要输出如下



反馈平均值



1 4.3(26/6 = 4.3)

2 3(18/6 = 3)

Facid Feedbackid FacQ1 FacQ2
1 1 5 4
2 1 4 3
3 1 4 2
1 2 5 4
2 2 4 2
3 2 4 3

Total 26 18

i want to sum the Facq1,FacQ2 and divide by number of rows.

I want output as follows

Feedbackid Average

1 4.3 (26/6 = 4.3)
2 3 (18/6 = 3)

推荐答案

select  CAST(sum(FacQ1)AS float)/count(*) , CAST(Sum(FacQ2)AS float)/count(*) from YourTable


试试这个.. :)





try this.. :)


select convert(float,sum(FacQ1))/count(*) as avg1,convert(float,sum(FacQ2))/count(*) as avg2 from TableName


这篇关于如何将sql server中的列值相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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