我有三个表,我想根据Table3的行值来计算每一行。例如,我有以下表格:
表1是完成一般数据输入的地方:
表1
| Day | Task | Est_Hours | Total_Hrs | MaxHours |
| Monday | General | 8 | 8 | 8 |
| Tuesday | Admin | 5 | 5 | 5 |
表2是我们进行估算的地方
表2
| Task | TotalHrs |
| General | 8 |
| Admin | 5 |
然后在第三个表格中是表2中每项任务的费率
表3
| Task | Rate |
| General | 11.5 |
| Admin | 8.50 |
我能够处理此查询
SELECT t2.Task,
t1.Est_Hours,
t1.Total_Hrs,
t1.MaxHours
FROM Table1 as t1
right JOIN Table2 as t2
ON t1.Task = t2.Task
此查询的输出是
| Task | Est_Hours | Total_Hrs | MaxHours |
| General | 8 | 8 | 8 |
| Admin | 5 | 5 | 5 |
我想在这里添加另一列来计算小时费率,使其看起来像
| Task | Est_Hours | Total_Hrs | MaxHours | Rate |
| General | 8 | 8 | 8 | 92 |
| Admin | 5 | 5 | 5 | 42.50 |
其中列速率将参考表3中的比率。希望你们能帮助我。谢谢。
答案 0 :(得分:1)
我假设Rate列应该是Rate的Total_hrs倍?然后 -
SELECT t2.Task,
t1.Est_Hours,
t1.Total_Hrs,
t1.MaxHours,
(t1.Total_Hrs * t3.Rate) as Rate
FROM Table1 as t1
JOIN Table2 as t2 ON t1.Task = t2.Task
JOIN Table3 as t3 ON t1.Task = t3.Task