0
Adding up the Points of the same waiter (ex.: Juliana Oliveira => 100 + 123)
SELECT g.nome Garcom,sum(p.pontos) TotalPontos
FROM tabela01 g
JOIN tabela02 p ON p.garcom_id = g.id
GROUP BY g.nome
ORDER BY sum(p.pontos) DESC,g.nome
Without adding, catching the biggest point of every waiter
SELECT g.nome Garcom,max(p.pontos) maior
FROM tabela01 g
JOIN tabela02 p ON p.garcom_id = g.id
GROUP BY g.nome
ORDER BY max(p.pontos) DESC,g.nome
P.S.: Change the tabela01
and tabela02
for the names of the respective tables
If you want the first records Filtre by the first N records Voce wants and you did not inform what type of database is.
Sqlserver would add a TOP N right after the select (SELECT TOP 10 ....
);
Postgresql would add a LIMIT N at the end (ORDER BY ..... LIMIT 10
);
Oracle is beemmm more complicated, nor will post here, I will inform a link (I found on google) Oracle
Mysql equals Postgresql, uses LIMIT at the end
The names that appear in table 01 are the names of the waiters?
– Kleber Silva