我有以下工作查询,但似乎必须有一种更简单的方法来编写它。我已经尽我所能清理了查询,并将其粘贴在下面,感谢您给我的任何帮助/建议。
样本结果:
UserID | MemberCount | TotalCheck | TotalCCs
----------------------------------------------
123 | 75 | 25 | 0
456 | 74 | 129 | 156
示例查询:
Select BPE.UserID
,ISNULL((Select COUNT(*)
From clients
where fac_id = BPE.billpay_FacID
and clt_web_type = 1
and clt_relationship = 0),'0') as MemberCount
,(Select SUM(achorder_total) as ACHTotal
from ACHOrder
where achorder_siteid = BPE.siteID
and ACHOrder_PayDate between @Start and @End
and ACHOrder_Status not in ('Voided','Reversed')) As TotalChecks
,(Select SUM(CCorder_total) as CCTotal
from CCOrder
where CCorder_siteid = BPE.siteID
and CCOrder_PayDate between @Start and @End
and CCOrder_Status not in ('Voided','Reversed')) As TotalCCs
From BillingEnabled BPE
Order By BPE.UserID
有没有更简单的方法来构造这个查询?