1
Talk guys, all right?
I have this table
Table EMPREGADO_PROJETO
+--------------+-------------+-------+
| rg_empregado | num_projeto | horas |
+--------------+-------------+-------+
| 20202020 | 5 | 10 |
+--------------+-------------+-------+
| 20202020 | 10 | 25 |
+--------------+-------------+-------+
| 30303030 | 5 | 35 |
+--------------+-------------+-------+
| 40404040 | 20 | 50 |
+--------------+-------------+-------+
| 50505050 | 20 | 35 |
+--------------+-------------+-------+
I need to show you which project has the most hours. For this I will need to join the projects with the same number, add up their hours and show what is the largest sum. The sum I’m managing to show, all that remains is to identify which is the project number that this sum belongs to.
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 response worked, I only had to add the top 1 in the first select and it worked exactly as I wanted it.
thinker, don’t keep posting updates of the question here below, as if they were answers. Click [Edit] and add direct to the question, and delete the other posts.
– user28595
okay, it’s done.
– thinker