tags:

views:

49

answers:

1

hi there i want to design a football result table from a existing database structure.

TEAM(id, name)
GAME(id, team1id, team2id, goalsTeam1, goalsTeam2)

the result table should look like:

name games points
name games points
name games points

(the points can be get by looking who hase make more goles (win=3,draw=1,loose=0))

i dont know how to make the query can somebody help me?

A: 

Can't you do that programmatically? I would join the two tables, so that all relevant columns are in the result set, iterate the result set, calculate and store the result in something like a hashtable or so.

gemue
No because i want to make a view of it
latte_makao
I doubt that there is a solution with a single sql statement. The aggregation and calculation with the external knowledge (win=3, draw=1, loose=0 and win=[goalsTeam1-goalsTeam2) > 0 and so on) is quite complex and you will also run into grouping problems, because the same team will probably occur in both team columns. What about triggering a stored procedure triggered on inserting a game in the game table that does the calculation programmatically and writes an additional result table?
gemue