Count Rows On a Condition in SQL SERVER 2000 -


i want fetch data in following format sql server 2000

department | totalpresent | employee | officer xyz              12           6          6 

i running query

select     a.department,            count(emp_id) totalpresent,            case                       when a.type = 'employee' count(a.type)                       else 0            end employee,            case                       when a.type = 'officer' count(a.type)                       else 0            end officer       attendancelog m inner join employeedata on         m.emp_id = a.emp_id groupby a.type,            a.department 

when run query sort of data not correct

department | totalpresent | employee | officer     xyz              12           6         0     xyz              12           0         6 

please correct me seems problem why returning me same records twice fulfilling condition

all want count rows on condition whether type employee or officer

remove type group by , move case inside sum():

select a.department, count(emp_id) totalpresent,        sum(case when a.type = 'employee' 1 else 0 end) employee,        sum(case when a.type = 'officer' 1 else 0 end) officer attendancelog m inner join      employeedata      on m.emp_id = a.emp_id groupby a.department; 

also, upgrade sql server. sql server 2000 has been unsupported years. should try use supported software.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -