| Author |
Topic  |
|
|
aashirwaads
Starting Member
8 Posts |
Posted - 07/30/2007 : 08:34:03
|
Hi friends,
Please guide me as I am stuck in a query
I have got 3 queries
1.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
Sweden
29138 Posts |
Posted - 07/30/2007 : 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 NotClerks FROM Employees GROUP BY EmployeeID, EmployeeName ORDER BY EmployeeID, EmployeeName
E 12°55'05.25" N 56°04'39.16" |
Edited by - SwePeso on 07/30/2007 08:47:54 |
 |
|
|
madhivanan
Premature Yak Congratulator
India
22461 Posts |
Posted - 07/30/2007 : 10:14:17
|
Also read about Cross-tab reports in sql server help file
Madhivanan
Failing to plan is Planning to fail |
 |
|
| |
Topic  |
|
|
|