Hey fellas,
I got a small problem where I'd hope someone could nudge me in the right direction as I'm not as skilled with table joining or cross-queries... At least I think that's what I need.
Imagine this, I got 2 databases. One with a long list of numbers and other unimportant stuff, and a 2nd with many entries each matching one or another number from table 1. There are often several entries with the same number in 2... The 2nd table also has a procentage with each entry. Heres a visual:
Table 1:
+---+
| 1 |
| 2 |
| 3 |
| 4 |
| n |
+---+ n = n-finity of course...
Table 2:
+---+----+
| 1 | 63 |
| 1 | 25 |
| 2 | 93 |
| 4 | 23 |
| 4 | 83 |
| 4 | 67 |
| n | xx |
+---+----+
What I'm wondering is - Is it possible to get MySQL to do some cross table calculations? For example - I want to list the whole of table 1, and at the same time make a field next to each entry which is an average out of 2nd field in table 2. Only from the fields which actually refers to each entry of course. I guess it would look like this
+---+----+
| 1 | 44 | ((63 + 25) / 2)
| 2 | 93 | (93 / 1)
| 3 | -- |
| 4 |~59 | ((23 + 83 + 67) /3)
+---+----+
I fear its probably too complex, or? I'm using PHP in conjunction with MySQL and I don't want to store the averages because they have to be dynamic with each request...
Thanks in advance,
Gazoo...