Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
aashirwaads
Starting Member
8 Posts |
Posted - 2007-07-30 : 08:34:03
|
Hi friends,Please guide me as I am stuck in a queryI have got 3 queries1.columns-employee_id,employee_name,count(sales role)2.columns-employee_id,employee_name,count(employees who are clerks)3.columns-employee_id,employee_name,count(employees who are not clerks)now I want to join these three queries so that the output is shown as one table as below employee_id,employee_name,count(sales role),count(employees who are clerks),count(employees who are not clerks) |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-30 : 08:46:49
|
Try something similar to this.SELECT EmployeeID, EmployeeName,COUNT(*) AS TotalRoles,SUM(CASE WHEN Role = 'clerk' THEN 1 ELSE 0 END) AS Clerks,SUM(CASE WHEN Role = 'clerk' THEN 0 ELSE 1 END) AS NotClerksFROM EmployeesGROUP BY EmployeeID, EmployeeNameORDER BY EmployeeID, EmployeeName E 12°55'05.25"N 56°04'39.16" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-30 : 10:14:17
|
Also read about Cross-tab reports in sql server help fileMadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|