N
N
Night_Harpy2020-07-18 12:27:28
MySQL
Night_Harpy, 2020-07-18 12:27:28

How to solve sql task?

I have never worked with pure sql, so I don't know how to solve it. There are two tables in the database:
5f12bf96a6209001926255.png
you need to display 3 employees (together with names) who have the most hours in total.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Pankov, 2020-07-18
@trapwalker

SELECT
  e.name, SUM(t.hours)
FROM 
  employees e
    JOIN time_reports t ON t.employee_id = e.id
GROUP BY e.id, e.name
ORDER BY 2 DESC
LIMIT 3

T
ThunderCat, 2020-07-18
@ThunderCat

select name, sum(hours) hours
from names and
left join time t
on id = t.employ_id
group buy t.emploi_id
order buy hours desk limit 3
something like this...

E
Eugene, 2020-07-18
@Nc_Soft

SELECT employees.name, SUM(time_reports.hours) as hours
FROM time_reports 
LEFT JOIN employees ON time_reports.employee_id = employees.id
GROUP BY time_reports.employee_id
ORDER BY hours DESC
LIMIT 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question