select a.*,b.tr from
(
select name,sum(tm)as tm from
(
select * from ta
union all
select * from ta
union all
select * from ta
)a group by name
)a join tr b on a.name=b.name
(
select name,sum(tm)as tm from
(
select * from ta
union all
select * from ta
union all
select * from ta
)a group by name
)a join tr b on a.name=b.name
(
select * from ta
union all
select * from ta
union all
select * from ta
)a group by name