我的 sql 语句看起来像这样。
SELECT fe.AdmSiteID,A.SiteDescription,
'' AS SNAP, '' AS TANF, '' AS Foster, '' AS FDPIR, '' AS Homeless, '' AS Migrant, '' AS Runaway,
'' AS HeadStart, '' AS EvenStart, '' AS DirectCertified, '' AS NoApplication, '' AS FreeIncome, '' AS ReducedIncome,
'' AS RefusedBenefits,'' AS DeniedIncome, '' AS DeniedVerification, '' AS DeniedNotValid, '' AS TempFreeGrace, '' AS TempReducedGrace,
'' AS DeniedInactive, '' AS DNQ, '' AS ExpiredGrace
FROM FarEligibilityEnrollmentCounts fe
inner join AdmSites A on fe.AdmSiteID = A.AdmSiteID
GROUP BY fe.AdmSiteID,A.SiteDescription
union
select fe.AdmSiteID,A.SiteDescription,sum(PatronCount) as SNAP, '' AS TANF, '' AS Foster, '' AS FDPIR, '' AS Homeless, '' AS Migrant, '' AS Runaway,
'' AS HeadStart, '' AS EvenStart, '' AS DirectCertified, '' AS NoApplication, '' AS FreeIncome, '' AS ReducedIncome,
'' AS RefusedBenefits,'' AS DeniedIncome, '' AS DeniedVerification, '' AS DeniedNotValid, '' AS TempFreeGrace, '' AS TempReducedGrace,
'' AS DeniedInactive, '' AS DNQ, '' AS ExpiredGrace
from FarEligibilityEnrollmentCounts fe
inner join AdmSites A on fe.AdmSiteID = A.AdmSiteID
where fe.FarStudentCaseID = '4FA4AED1-75C9-4CB4-9FF2-102C2D964CC1'
Group BY fe.AdmSiteID,A.SiteDescription
union
select fe.AdmSiteID,A.SiteDescription,'' as SNAP, sum(PatronCount) AS TANF, '' AS Foster, '' AS FDPIR, '' AS Homeless, '' AS Migrant, '' AS Runaway,
'' AS HeadStart, '' AS EvenStart, '' AS DirectCertified, '' AS NoApplication, '' AS FreeIncome, '' AS ReducedIncome,
'' AS RefusedBenefits,'' AS DeniedIncome, '' AS DeniedVerification, '' AS DeniedNotValid, '' AS TempFreeGrace, '' AS TempReducedGrace,
'' AS DeniedInactive, '' AS DNQ, '' AS ExpiredGrace
from FarEligibilityEnrollmentCounts fe
inner join AdmSites A on fe.AdmSiteID = A.AdmSiteID
where fe.FarStudentCaseID = 'B348D33C-5C32-4CFE-B508-1E0CE2A9D428'
Group BY fe.AdmSiteID,A.SiteDescription
查询返回如下所示的数据。
AE1EF8E3-A093-410D-A02A-2B6DB334C758 Dowell Middle School 0 0
0359AF48-882F-4D54-B39D-341B17D64403 Evans Middle School 0 0
0359AF48-882F-4D54-B39D-341B17D64403 Evans Middle School 0 1595
0359AF48-882F-4D54-B39D-341B17D64403 Evans Middle School 1045 0
我正在尝试合并 3 Evans Middle School 列,所以最终结果应该看起来像
AE1EF8E3-A093-410D-A02A-2B6DB334C758 Dowell Middle School 0 0
0359AF48-882F-4D54-B39D-341B17D64403 Evans Middle School 1045 1595
有没有办法做到这一点?