Skip to content
Advertisement

Sum By Criteria in specific column

I have questions about SQL Server query for SUM.

I have 2 tables:

1) EmployeesAtt (EId, EName, Stats) -> I have some criteria for Stats (0 = late, 1 = overtime, 2 = normal)

2) AttLogs (ID, EId, late, overtime, normal)

From EmployeesAtt table, I want to SUM the EId And Stats in dedicated column in AttLogs looks like this one:

this is what I’ve done so far:

but the results are not as I expected above.

Advertisement

Answer

You need to use conditional aggregation and sum/count your CASE expressions:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement