认为我的问题是我试图在同一查询中求和,这可以在php中实现以避免这种情况吗? “记录”列显示记录计数,而“成本”将成本加总,这很好,但是我想对这两个列求和以得出总计?

Select
  tblcontacts.ContactFullName As Name,
  Count(tblcases.CaseID)As Records,
  Sum(tblcases.CaseCommission) As Costs
From
  tblcontacts Inner Join
  tblcases On tblcontacts.ContactID =
    tblcases.ContactAssignedTo
Group By
  tblcontacts.ContactFullName

最佳答案

最后使用With RollUp。一次性扫描表,因此它以性能为导向。

Select
  tblcontacts.ContactFullName As Name,
  Count(tblcases.CaseID)As Records,
  Sum(tblcases.CaseCommission) As Costs
From
  tblcontacts Inner Join
  tblcases On tblcontacts.ContactID =
    tblcases.ContactAssignedTo
Group By
  tblcontacts.ContactFullName
WITH RollUP


Refer here for more details

10-05 20:08