我有以下有效的查询语句,但似乎必须有更简单的编写方式。我已尽力整理了查询语句,并在下面粘贴了它,非常感谢您能给我任何帮助/建议。
示例结果:
有没有更简单的构建这个查询的方法?
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
有没有更简单的构建这个查询的方法?