select 产品,sum(访问数) as 访问数,convert(varchar(7),日期,120) as'月份' from 表名 group by 产品,convert(varchar(7),日期,120),
select 产品,访问数=sum(访问数) from 表名 group by 产品
==== 运用sum求和聚合函数 如上写法,或者如下: SQL codeselect产品,sum(访问数) as 访问数 from表名groupby产品
--创建测试表 create table testone ( id int identity(1,1), 产品 varchar(1) not null, 访问数 int not null, 日期 varchar(8) not null ) go--创建测试数据 insert into testone select 'a',1,'2006-8-1' union select 'b',3,'2006-8-1' union select 'c',2,'2006-8-1' union select 'e',2,'2006-8-1' union select 'a',5,'2006-8-2' union select 'b',1,'2006-8-2' union select 'c',4,'2006-8-2' union select 'f',4,'2006-8-2' go--SQL代码select 产品,总访问数=sum(访问数) from testone group by 产品--结果 a 6 b 4 c 6 e 2 f 4
====
运用sum求和聚合函数
如上写法,或者如下:
SQL codeselect产品,sum(访问数) as 访问数 from表名groupby产品
create table testone
(
id int identity(1,1),
产品 varchar(1) not null,
访问数 int not null,
日期 varchar(8) not null
)
go--创建测试数据
insert into testone
select 'a',1,'2006-8-1'
union
select 'b',3,'2006-8-1'
union
select 'c',2,'2006-8-1'
union
select 'e',2,'2006-8-1'
union
select 'a',5,'2006-8-2'
union
select 'b',1,'2006-8-2'
union
select 'c',4,'2006-8-2'
union
select 'f',4,'2006-8-2'
go--SQL代码select 产品,总访问数=sum(访问数) from testone group by 产品--结果
a 6
b 4
c 6
e 2
f 4
FROM 表名
group by 产品