Author |
Topic |
Syima
Starting Member
13 Posts |
Posted - 2007-09-27 : 01:21:37
|
Hi there,1. Assuming I have below table:Projectid, Dept, Budgeted, Approved, StatusA1, Audit, Yes, No, StartedB1, HR, No, Yes, StartedC1, IT, Yes, Yes, Not StartedD1, Audit, Yes, Yes, Dropped2. Below are the 2 queries createdselect dept, count(projectid) from table where budgeted = 'yes' group by deptselect dept, count(projectid) from table where budgeted = 'yes' and (approved = 'yes' or status = 'started') group by dept3. How to join the above 2 queries for me to get the following resultDept, Budgeted, Exp1Audit, 2, 1IT, 1, 1HR, 0, 0 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-27 : 01:29:37
|
[code]SELECT Dept, Budgeted = SUM(CASE WHEN Budgeted = 'Yes' THEN 1 ELSE 0 END), Exp1 = SUM(CASE WHEN Budgeted = 'Yes' AND (Approved = 'Yes' OR Status = 'Started') THEN 1 ELSE 0 END)FROM table1GROUP BY Dept[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
Syima
Starting Member
13 Posts |
Posted - 2007-09-27 : 01:40:51
|
Hi there,thx for d reply. it worx. :) |
 |
|
|
|
|