日期:2014-05-16 浏览次数:20606 次
create table A
(
id int,
name varchar(10),
number int
)
insert into A
select '1', 'li', '22'
union all
select '1', 'li', '38'
union all
select '2', 'wang', '50'
union all
select '2', 'wang', '64'
union all
select '3', 'zhao', '70'
union all
select '3', 'zhao', '55'
create table B
(
id int,
roleid int
)
insert into B
select 1, 0 union all
select 2, 0 union all
select 3, 1
select * from A;
select * from B;
select B.roleid,SUM(A.number) as number from A inner join B on A.id=B.id
group by
B.roleid
roleid number
0 174
1 125