2014-03-02 26 views
0

我在我的数据库中有两个表格。第一个是员工,其中包含所有员工和小时工资。乘以不同表格的值

staffid  staffname wage 
----------------------------- 
1   Joe   15 
2   Bill  14 

然后有小时,其中包含每个员工工作的小时数。

staffid  date   hours 
------------------------------ 
1   03.02.2014 8 
2   03.02.2014 6 

现在我想要做的是显示工作人员每天制作的金额。 所以输出可能是这个样子:

staffid  date  amount 
------------------------------ 
1   03.02.2014 120 
2   03.02.2014 84 

我会怎么做这与SQL?谢谢!

+0

有人可能在同一天有两个记录吗? (例如,如果他/她工作了两个不同的班次。) –

回答

1
select s.staffid, 
     h.date, 
     h.hours * s.wage as amount 
from staff s 
inner join hours h on h.staffid = s.staffid 
+0

工作完美,谢谢! – Boxiom