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 |
marxdo
Starting Member
6 Posts |
Posted - 2012-01-05 : 04:37:33
|
hi i have a problem on the group by clause that causes wrong data to be returned. i need to have a total count that will output thisOD WithCSO WithoutCSOCWRD 117 80EARD 133 73SARD 195 131SERD 195 134i have a query for each and it is working but when i merged them to this querySELECT ProjectDetails.OD, Count(ProjectDetails.ProjectID) AS [WithCSO], (select count(ProjectDetails.OD) from ProjectDetails where (ProjectDetails.CSO_Participation)='Yes') as withoutcsoFROM ProjectDetailsWHERE (((ProjectDetails.CSO_Participation)<>'NA'))GROUP BY ProjectDetails.OD;The data becameOD WithCSO WithoutCSOCWRD 117 418EARD 133 418SARD 195 418SERD 195 418please help what should i do to get the actual desired data as seen on the top, it seems the group by filed is not being detcted.thank you |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-01-09 : 01:59:28
|
Try this codeSELECT ProjectDetails.OD, Count(ProjectDetails.ProjectID) AS [WithCSO], sum(iff(CSO_Participation='yes',1,0)) as withoutcsoFROM ProjectDetailsWHERE (((ProjectDetails.CSO_Participation)<>'NA'))GROUP BY ProjectDetails.OD;MadhivananFailing to plan is Planning to fail |
|
|
|
|
|