Talk about it, all right?
I have this table
EMPLOYEE_PROJECT Table
+--------------+-------------+-------+
| rg_empregado | num_projeto | horas |
+--------------+-------------+-------+
| 20202020 | 5 | 10 |
+--------------+-------------+-------+
| 20202020 | 10 | 25 |
+--------------+-------------+-------+
| 30303030 | 5 | 35 |
+--------------+-------------+-------+
| 40404040 | 20 | 50 |
+--------------+-------------+-------+
| 50505050 | 20 | 35 |
+--------------+-------------+-------+
I need to show which project has the most hours. For this I will need to join the projects with the same number, add their hours and show which is the largest sum. The sum I am able to show, it is only necessary to identify which is the number of the project that this sum belongs.
Here's what I've been able to do so far.
SELECT MAX(HORAS_TOTAIS) AS MAIOR_CARGA_HORARIA FROM
(SELECT DISTINCT NUM_PROJETO, SUM(HORAS) AS HORAS_TOTAIS FROM EMPREGADO_PROJETO
GROUP BY NUM_PROJETO) EMPREGADO_PROJETO
Raphael's answer worked out, I just needed to add the top 1 on the first select and it worked exactly as I wanted it to.