Hello,
Starting to teach myself SQL. Goes fine except that I run into new problems every now and again (as expected ;-).
I have 2 tables:
1 Games with 1 record for every game played. Two (different) players with their results. Fields: Gamenr, player1, pl1_points, pl1_turns, player2, pl2_points, pl2_turns etc. In player1 and player2 there is the plyer_id from
2 Players with id, name, adres etc.
For every player I have to Count the gamenr, sum the points etc but my problem is that there are records where player_id 1 is in player1 and in other records player_id 1 is player2.
I think the solution is in joins but in my new books I couldn't find a proper solution (my fault of course).
I have the following:
SELECT ronde, speler1, L1.naam, COUNT( wnr ) AS "Gespeeld", SUM( s1_car ) , SUM( s1_brtn )
FROM (
wedstrijden1 AS W1
INNER JOIN leden AS L1 ON W1.speler1 = L1.lidnr
INNER JOIN leden AS L2 ON W1.speler2 = L2.lidnr
)
WHERE seizoen = "2006/07"
GROUP BY ronde, speler1, L1.naam
ORDER BY 1 , 2,
I know some fields are in dutch, but hope this gives enough info. I also know the select is far from right, but I tried IF's , other joins (left , right) but I don't get any further so.....
I could really use some advice here
Thanks in advance
Bauke (Holland)
Starting to teach myself SQL. Goes fine except that I run into new problems every now and again (as expected ;-).
I have 2 tables:
1 Games with 1 record for every game played. Two (different) players with their results. Fields: Gamenr, player1, pl1_points, pl1_turns, player2, pl2_points, pl2_turns etc. In player1 and player2 there is the plyer_id from
2 Players with id, name, adres etc.
For every player I have to Count the gamenr, sum the points etc but my problem is that there are records where player_id 1 is in player1 and in other records player_id 1 is player2.
I think the solution is in joins but in my new books I couldn't find a proper solution (my fault of course).
I have the following:
SELECT ronde, speler1, L1.naam, COUNT( wnr ) AS "Gespeeld", SUM( s1_car ) , SUM( s1_brtn )
FROM (
wedstrijden1 AS W1
INNER JOIN leden AS L1 ON W1.speler1 = L1.lidnr
INNER JOIN leden AS L2 ON W1.speler2 = L2.lidnr
)
WHERE seizoen = "2006/07"
GROUP BY ronde, speler1, L1.naam
ORDER BY 1 , 2,
I know some fields are in dutch, but hope this gives enough info. I also know the select is far from right, but I tried IF's , other joins (left , right) but I don't get any further so.....
I could really use some advice here
Thanks in advance
Bauke (Holland)