Question : group by and sum function in SQL

I'm trying to create a time management application where users can log the amount of time they spend on each project.

The fields are:
firstName, lastName, projectName, date, timeSpent

Users can add multiple records for each project per day and a project can take multiple days to complete so how can I
1. sum the hours spent on a project for that day
2. sort by last name

Answer : group by and sum function in SQL

check this
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
SELECT
        FirstName, 
        LastName,  
        CONVERT(VARCHAR(10), [Date], 101),
        SUM(TimeSpent),
        S.ProjectName, 
        S.UserId,               
        FROM [Project] AS S (NOLOCK)
        INNER JOIN [User] AS U (NOLOCK) ON S.UserId = U.Id
        WHERE S.LocationId = @LocationId 
        GROUP BY LastName, FirstName, ProjectName, CONVERT(VARCHAR(10), [Date], 101), UserId;
Random Solutions  
 
programming4us programming4us