SELECT
Districts.DistrictDescription,Count(SchoolDetail.Name) As Responded,
Sum(Case When School_WASH.WaterAssetCondition = 'Improved' Then 1 Else 0 End) as H2Improved,
Sum(Case When School_WASH.WaterAssetCondition = 'Unimproved' Then 1 Else 0 End) as H2NotImproved,
Sum(Case When School_WASH.WaterTypeFunc = 'Functional' Then 1 Else 0 End) as H2Func,
Sum(Case When School_WASH.WaterTypeFunc = 'Not Functional' Then 1 Else 0 End) as H2NotFunc,
Sum(Case When School_WASH.ToiletsImproved = 'Improved' Then 1 Else 0 End) as ToiletsImproved,
Sum(Case When School_WASH.ToiletsImproved = 'Unimproved' Then 1 Else 0 End) as ToiletsUnimproved,
Sum(Case When School_WASH.ToiletsFunc = 'Functional' Then 1 Else 0 End) as ToiletsFunc,
Sum(Case When School_WASH.ToiletsFunc = 'Not Functional' Then 1 Else 0 End) as ToiletsNotFunc,
Sum(Case When School_WASH.FuncToiletsAccessible = 'Yes' Then 1 Else 0 End) as Accessible,
Sum(Case When School_WASH.FuncToiletsAccessible = 'No' Then 1 Else 0 End) as NotAccessible,
Sum(Case When School_WASH.StudentToiltesSexSeparated = 'Yes' Then 1 Else 0 End) as SexSep,
Sum(Case When School_WASH.StudentToiltesSexSeparated = 'No' Then 1 Else 0 End) as NoSexSep,
Sum(Case When School_WASH.HandWashFacWithWater = 'Yes' Then 1 Else 0 End) as HandWashWater,
Sum(Case When School_WASH.HandWashFacWithWater = 'No' Then 1 Else 0 End) as NoHandWashWater,
Sum(Case When School_WASH.HandWashFacWithWaterSoap = 'Yes' Then 1 Else 0 End) as HandWashWaterSoap,
Sum(Case When School_WASH.HandWashFacWithWaterSoap = 'No' Then 1 Else 0 End) as NoHandWashWaterSoap
FROM
Districts
INNER JOIN
SchoolDetail ON Districts.ID = SchoolDetail.DistrictID
INNER JOIN
School_WASH ON SchoolDetail.Code = School_WASH.SchoolCode
WHERE
School_WASH.SchoolYear = '2016'
GROUP BY
Districts.DistrictDescription
答案 0 :(得分:0)
如果我理解你在寻找什么,你只需要将你的计数作为子查询运行
替换这个:
(select count(Name) from SchoolDetail) As Responded
通过
zip