I am new to sql ,I have a table like this
Emp_id | Emp_NAME | EMP_GRADE 1 Test1 A1 2 Test2 A2 3 Test3 A3 4 Test4 A4 6 Test5 A1 7 Test6 A2 8 Test7 A3
I need to get the count of the employee in each grade , in which the final ouput will be "2 - 2 - 2 - 1 " in a single column where output refers (Count of Employee in each Grade ie A1(2) - A2(2)- A3(2) -A4(1)) . can anyone give sql query for this. I hope we dont need cursor for this .
SQL Fiddle example
If you are filtering but still want to return results for every grade, you will need a self-join to get the full list of grades. Here's one way:
SQL Fiddle example
Use:
Update:
This should work:
Hope that helps. Keep learning SQL.