group columns in mysql

Asked

Viewed 138 times

1

Have these Insert in the table tabela partidas

I would like an sql me returns the total points of the type team:

time - points

Uruguai - 9

Russia - 6

Rabia - 3

Gito - 0

2 answers

2

This code solves:

SELECT TIME, SUM(J.PONTOS) AS PONTOS FROM (
   SELECT TIME1 AS TIME, PONTOSTIME1 AS PONTOS
      FROM JOGOS
   UNION ALL
   SELECT TIME2 AS TIME, PONTOSTIME2 AS PONTOS
      FROM JOGOS) AS J
GROUP BY TIME
ORDER BY PONTOS DESC

Results in:

TIME    PONTOS
uruguai 9
russia  6
arabia  3
egito   0

See working in http://sqlfiddle.com/#! 9/292934/25

  • thank you very much worked perfectly

  • Thank you. To help the site, please check the 'accepted' option (check icon below the reply score)

0


See if it suits you:

with pontuacao_times as(
select time1       as time
      ,pontostime1 as pontos
  from Sua_tabela
union all
select time2       as time
      ,pontostime2 as pontos
  from Sua_tabela)
select time
      ,pontos 
  from pontucao_times
 group by time, pontos;
  • thanks for the help

  • For nothing, you came to test my answer? It worked?

Browser other questions tagged

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