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

这样的查询怎样写
A表   ID,Name
B表   Index,Name,Time
怎样建立一个查询?
获得:ID,Name,CountTime
其中CountTime是B.Name=A.Name的B.Time的和。

------解决方案--------------------
select id,name,sum(CountTime) as CountTime
from a表,b表
where B.Name=A.Name
group by id,name
------解决方案--------------------
Select A.ID,A.Name,temp.CountTime
From A Left outer join (Select Name,Sum(Time) as CountTime From B Group By Name) temp
on A.Name=temp.Name