我有一个交叉表查询,可以很好地根据某个记录状态汇总所有记录 [活动、结束等]
Select
c.ReferralName,
Sum((d.CaseStatusName) = 'Active') As Active,
Sum((d.CaseStatusName) = 'Completed') As Completed,
Sum((d.CaseStatusName) = 'Submitted') As Submitted,
Count(b.CaseID) As Total,
Sum(b.LeadCost) As Cost
From
tblcontacts a Inner Join
tblcases b On a.ContactID = b.ContactID Inner Join
tblreferral c On c.RefferalID = a.ContactReferrelSource Inner Join
tblcasestatus d On d.CaseStatusID = b.CaseStatusName
Group By
c.ReferralName With Rollup
这很好用,但我现在还想运行一个查询,将 d.CaseStatusName 的总和替换为 b.LeadCost 的总和,但找不到实现它的方法!
我认为如果 d.CaseStatusName='Active' 等,我需要有 b.LeadCost 的总和等
非常感谢任何帮助。