查找另一个表并乘以行

时间:2018-04-25 03:07:48

标签: sql

enter image description here

尝试将表A与表B相乘。在表A列Total Ex:查询Activity 1 STD Time来自Table BActivity 2 {{1}来自STD time

1 个答案:

答案 0 :(得分:0)

要执行乘法,您需要使用union all

select *, (tb.STDTime * t.Time) as MultiTime
from (
    select TeamName, 'Activity1' as Activity, Activity1 as Time
    from tableA UNION ALL
    select TeamName, 'Activity2' as Activity,  Activity2 as Time
    from tableA UNION ALL
    select TeamName, 'Activity3' as Activity,  Activity3 as Time
    from tableA UNION ALL
    . . .
    select TeamName, 'Activity7' as Activity,  Activity4 as Time
    from tableA
) t inner join tableB tb on tb.Activity = t.Activity;