SQL Statment of SUM rows with conditions

I have user_id = 23 that I want to query, I also have a table work_log include project_id, user_id, log_hours like this:

id | project_id | user_id | log_hours
1  | 23         | 23      |  2.5
1  | 3          | 23      |  3
1  | 23         | 23      |  1
1  | 24         | 23      |  3
1  | 24         | 23      |  1.5
1  | 23         | 23      |  0.5

But now I want sum all log_hours for each with result will have:

project_id | sum_of_log_hours
23         | 4
3          | 3
24         | 4.5

How can I write SQL statement to have that result?


Source: sql

Leave a Reply