Reputation: 1
Here is my problem:
I have two tables, lets name it "main" and "Ex"
table main looks like: (pseudo code)
nr | points|
A1 | 5 |
A2 | 3 |
A3 | 4 |
B1 | 2 |
B2 | 4 |
Table ex looks like:
Pnr | Ex1 | Ex2 | Pmax |
P1 | A1 | B1 | 7 [calculated from table main]
P2 | A2 | B1 | 5 [calculated from table main]
How to I get a realation between these two tables, to calculate Pmax?
thx a lot.
c.
Upvotes: 0
Views: 105
Reputation: 247870
It seems like this is what you want:
select e.pnr,
e.ex1,
e.ex2,
sum(points) Pmax
from main m
inner join ex e
on m.nr = e.ex1
or m.nr = e.ex2
group by e.pnr, e.ex1, e.ex2
Upvotes: 2