我正在尝试计算每个客户的总发票数。我从中提取信息的表是一个交易表,每个发票号可能有多个条目([凭证号])。此查询的结果是为每个客户提供了一些行数,但没有明确的发票数。我不知道怎么写这个。
SELECT top 20 a.[Sell-to Customer No_],
b.[Name],
sum(a.[Amount])as 'Total Sales Amount',
avg(a.Amount) as 'Average per Purchase',
count(a.[Document No_]) as 'Total Invoices'
FROM [Sales Invoice Line] a left outer join [Customer] b
ON a.[Sell-to Customer No_] = b.[No_]
WHERE [Posting Group] like 'PAR'
and a.[Shipment Date] >= '10-01-2013'
GROUP BY a.[Sell-to Customer No_], b.[Name]
答案 0 :(得分:0)
尝试使用:
count(distinct...)
而不是
count(...)