2

I have done quite a bit of research and found some useful sql examples but can't seem to get exactly what I want.

1. Employee Table
ID, EmployeeName

2. Absence Table
ID, Employee_ID, Reason

I need a report with distinct first letters of the employee's name and another column with a count of how many times that certain category was absent!

1
  • Nope, by category I meant the count of the items in the first column. sorry Commented Aug 24, 2011 at 17:02

2 Answers 2

2
Select LEFT(a.EmployeeName, <number of chars you want>), COUNT(b.EmployeeId) 
FROM Employee a, Absence b 
WHERE a.ID = b.Employee_ID GROUP BY a.ID 
Sign up to request clarification or add additional context in comments.

Comments

1

Try this query

select substr(EmployeeName, 1, 1) as emp_name, count(*) from
Employee e inner join Absence a on e.ID=a.Employee_ID
group by emp_name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.