十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
select sum(求和栏位),sum(求和栏位)/count(*) --总和,平均值
网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、微信平台小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了富顺免费建站欢迎大家使用!
from 表名
select t1. mingchen,avg(t2.fenshu)
from zhibiao as t1
inner join pingjia_xuanxian as t2
on t1.id=t2.id
group by t1.mingchen
select convert(varchar,time,23),datepart(hh,time),avg(valueavg),max(valueavg)
from tb group by convert(varchar,time,23),datepart(hh,time)
SELECT 省, 市, 县, year(日期) 年份, AVG(ABS(闪电强度)) 闪电强度绝对值的平均值
FROM HUBEISHENG
GROUP BY 省, 市, 县,year(日期)
--已出结果 SQLSERVER2000
--生成测试数据
CREATE TABLE TestA
(
a int,
b int,
c int,
time datetime
)
INSERT INTO TestA
SELECT 12,13,45,'2009-6-9 10:59:26'
UNION ALL
SELECT 11,41,43,'2009-6-9 10:59:30'
UNION ALL
SELECT 10,75,742,'2009-6-9 11:00:40'
UNION ALL
SELECT 78,72,56,'2009-6-9 11:30:50'
UNION ALL
SELECT 52,11,55,'2009-6-9 12:00:42'
UNION ALL
SELECT 11,41,43,'2009-6-9 12:59:30'
--查询结果
SELECT A*1.0/FCount AS A平均值,B*1.0/FCount AS B平均值,C*1.0/FCount AS C平均值,Time
FROM(
SELECT SUM(a)AS A,SUM(b)AS B,SUM(c)AS C,
CONVERT(char(10),time,121)+' '+LTRIM(DATEPART(hour,time))+':00:00' AS Time,COUNT(*)AS FCount
FROM TestA
GROUP BY CONVERT(char(10),time,121),DATEPART(hour,time)
)AS T
--SELECT 1/2 =0 SELECT 1./2 =0.5 SELECT 1.0/2=0.5