I have two tables i would like to join to show bonus earned this month and total this year.
First table: empl.
emplID | Name
1 | Bob
2 | James
Second table: Bonus.
empl_id | month | Bonus
1 | 1 | 1000
2 | 1 | 750
1 | 2 | 500
2 | 2 | 1000
1 | 3 | 250
2 | 3 | 500
The output im looking for is (bonus month 3):
Name | Bonus this month | Bonus total
Bob | 250 | 1750
James | 500 | 2250
This is the closest i have got and it fails. So if anyone can point me in the right direction i would be very thankful.
Failing query:
First table: empl.
emplID | Name
1 | Bob
2 | James
Second table: Bonus.
empl_id | month | Bonus
1 | 1 | 1000
2 | 1 | 750
1 | 2 | 500
2 | 2 | 1000
1 | 3 | 250
2 | 3 | 500
The output im looking for is (bonus month 3):
Name | Bonus this month | Bonus total
Bob | 250 | 1750
James | 500 | 2250
This is the closest i have got and it fails. So if anyone can point me in the right direction i would be very thankful.
Failing query:
Code:
[I]select e.name, sum(b.bonus) as total, sum(b1.bonus) as thismth from (empl as e INNER JOIN bonus as b on e.emplID=b.empl_id) INNER JOIN bonus as b1 on e.emplID=b1.empl_id group by e.name[/I]
Comment