Bank consultation does not match

Asked

Viewed 37 times

0

I want to use the agenda table to manage the ranking with php when displaying so it would be simpler and practical because the user add the game in the table, when it starts the game already caught by itself and if you need to edit a game that has passed is already updates everything at once, The problem is, I stalled on that part. in the table the columns Timea and timeb are foreign keys that has the possibility of a (team that fell in the column Timea) further down the spine timeb so I tried tying up by the name of the team that comes from the other table. my complicated to explain so if you have another logic to indicate thank you as it is for study I do not need to get stuck in a prospectus, the closest I could was this but the data does not match it adds +1 in some fields

SELECT R.r_time_id as ID_Equipe, t.nome_time as Nome_Equipe,
       SUM(A.jogoa*3) as Pontos,
       SUM(A.jogoa+ AG.jogob ) as Jogos,
       SUM(A.gola + AG.golb) as Total_Gol,
       COUNT(A.v_a + AG.v_b )AS VIT,COUNT(A.e_a + AG.e_b )AS EMP,
       COUNT(A.d_a + AG.d_b)AS DER
FROM `ranking` R
INNER JOIN agenda A ON A.timea=R.r_time_id
INNER JOIN times t ON R.r_time_id=t.id    
INNER JOIN agenda AG On Ag.timeb=R.r_time_id
WHERE R.r_time_id=1

tabela times tabela da agenda

  • What do you intend with COUNT(A.v_a + AG.v_b )?

  • I put the SQL incomplete and did not understand, but the idea is that it count the victory when the team falls in column a or column b

  • I recommend that you study how NULL is treated. An expression that contains NULL will always result in NULL and COUNT will always ignore NULL.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.