日期:2014-05-18  浏览次数:20376 次

求简单SQL
table1
品名     购买次数
name         times
电视               10
冰箱               30
空调               20
。。。。。。。。


table2
品名           销售员
电视               aa
冰箱               aa
空调               cc
电话               dd
。。。。。。。。

想要得到如下结果
销售员         总次数
aa                   40
cc                   20
.........

------解决方案--------------------
select b.销售员,sum(a.times) from table1 a,table2 b where a.name=b.品名 group by b.销售员
------解决方案--------------------
select table2.销售员,
[总次数]=sum(times)
from table1 join table2 on table1.name=table2.品名
group by table2.销售员
------解决方案--------------------
select
销售员=B.销售员,
总次数=sum(A.times)
from A
inner join B on A.name=B.品名
group by B.销售员