group columns in mysql

1

You have these insert in the table

I'd like an sql and it returns me the team total points type:

time - points

Uruguay - 9

russia - 6

arabia - 3

Egypt - 0

    
asked by anonymous 03.07.2018 / 02:34

2 answers

0

See if it caters to 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;
    
03.07.2018 / 02:48
2

This code resolves:

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 at link

    
03.07.2018 / 03:09