I have one ASSIGNMENT table that includes attributes (ID, FirstName, LastName, Project, Hours). I created my table and inserted values inside. However, I am unable to list the total hours spent on each project. I have multiple Projects, some that are repeated multiple times.
For example, Project '333' is repeated many times. I want to list the total hours spent on each project.
SELECT sum( Hours) as total_hours
FROM ASSIGNMENT
WHERE Project = Project;
and I got Total_hours 165, but not the total hours of each project
CodePudding user response:
Use GROUP BY
SELECT sum( Hours) as total_hours
FROM ASSIGNMENT
WHERE Project = Project
GROUP BY Project
CodePudding user response:
You can use group by. Your query will be:
SELECT sum(Hours) as total_hours
FROM ASSIGNMENT
WHERE Project = Project group by Project ;
CodePudding user response:
SELECT
DISTINCT(Project),SUM(Hours) AS TimeSpent
FROM ASSIGNMENT
GROUP BY Project;
