select depart,distinct name,sum(numb) from test group by name depart name 字符型的字段,numb是数字型的字段,但是我这样求不对,老是再distinct附近有问题 我要到达的目的是,name是可以重复的,比如dai用户名的人很多,我想求dai的numb的和,不知道我表达清楚了没有!
create table tb(depart char(3),name varchar(100),numb int)
insert into tb select '001','dai',20
union all select '001','dai',20
union all select '003','dai',20
union all select '005','wang',20
union all select '005','wang',20
union all select '006','deng',20
select * from tb
select distinct name ,depart,sum(numb) as sum_numb from tb group by name,depart
drop table tb
create table tb(depart char(3),name varchar(100),numb int)
insert into tb select '001','dai',20
union all select '002','dai',20
union all select '003','dai',20
union all select '004','wang',20
union all select '005','wang',20
union all select '006','deng',20
select * from tb
select distinct name ,sum(numb) as sum_numb from tb group by name
drop table tb