[Solved] Calculate number of leaves taken by Employee in a month in SQL Server


Use SUM and GROUP BY.

SELECT Empid, SUM([No of Days]) AS Days
FROM leavetable
GROUP BY Empid

Read more here GROUP BY and here SUM.

This would give you:

Empid Days
100   25

Or if you mean count the amount of times an employee has been off use Count.

SELECT Empid, Count(Leaveid) AS LeaveTotal 
FROM leavetable
GROUP BY Empid

Read more here COUNT.

This would give you:

Empid LeaveTotal
100   6

1

solved Calculate number of leaves taken by Employee in a month in SQL Server