嘿,我正在编写一份报告,详细说明客户的发票。有两个表Customer,Invoices。
我需要找出每位客户的发票数量,每位客户的发票总数,每位客户的平均发票总额,每位客户的平均发票数量。下面是一个类似的表结构。
客户: CustomerNo
发票: CustomerNo,InvoiceID,金额
有人可以帮忙吗?
答案 0 :(得分:0)
这是你在Sql Server中的做法,不确定它是否有用,因为我看到问题是针对Crystal Reports
SELECT CustomerNo,
COUNT(1) TotalNoOfInvoices,
SUM(Amount) TotalAmountOfInvoices
FROM Invoices
Group by CustomerNo
SELECT
COUNT(b.CustomerNo)/Count(distinct a.Customer) AvgNoOfInvoices,
SUM(b.Amount)/Count(distinct a.Customer) AvgAmountOfInvoices
FROM Customer A LEFT JOIN Invoices B
ON A.CustomerNo = B.CustomerNo