Sql卷起怀疑平均值是如何计算的 [英] Sql roll up doubt how average is calcualted

查看:71
本文介绍了Sql卷起怀疑平均值是如何计算的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-select * from sales



-select * from sales

EmpId	Yr	Sales
1	2005	12000.00
1	2006	18000.00
1	2007	25000.00
2	2005	15000.00
2	2006	6000.00
3	2006	20000.00
3	2007	24000.00





我试过这个:



I tried this :

select EMPID,sum(Sales) as [totalsalesemployeewise],AVG(Sales)[avgsalaryemployee] from sales
group by EmpId WITH ROLLUP







i得到的结果如下:




i got the result as below :

EMPID	totalsalesemployeewise	avgsalaryemployee
1	55000.00	                   18333.3333
2	21000.00	                   10500.00
3	44000.00	                   22000.00
NULL	120000.00	                   17142.8571





- 现在最后一栏120000是可以理解的。但我怎么得到这个17142.8571?



请帮助



--Now in the last column 120000 is understandable. But how i got this 17142.8571 ?

Kindly help

推荐答案

简单的数学。乘以行数(7),你会看到。
Simple math. Multiply by the number of rows (7), and you'll see.


这篇关于Sql卷起怀疑平均值是如何计算的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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