这是我的查询 - 通过 SAP 查询工具创建:
SELECT DISTINCT
T1.CardCode,
T1.CardName,
T1.Phone1,
T1.GroupCode,
T1.Territory,
T2.Street,
T2.Block,
T2.City,
T2.ZipCode,
T2.County,
T2.State,
T2.Country,
count(distinct(T3.DocEntry)) as NumberOfInvoices,
sum(distinct(T4.GTotal)) as InvoiceTotal
FROM
[ASAP].[dbo].[OCRD] as T1
INNER JOIN [ASAP].[dbo].[CRD1] as T2 ON T1.CardCode = T2.CardCode
INNER JOIN [ASAP].[dbo].[OINV] as T3 on T1.CardCode = T3.CardCode
INNER JOIN [ASAP].[dbo].[INV1] as T4 on T3.DocEntry = T4.DocEntry
WHERE
T1.Territory = [%0]
AND T3.DocDate >= [%1]
AND T3.DocDate <= [%2]
GROUP BY
T1.CardCode,
T1.CardName,
T1.Phone1,
T1.GroupCode,
T1.Territory,
T2.Street,
T2.Block,
T2.City,
T2.ZipCode,
T2.County,
T2.State,
T2.Country
这是我收到的错误 - 您可以清楚地看到我在 Group By 中有该字段:
- [Microsoft][SQL Native Client][SQL Server]列 'ASAP.dbo.OCRD.Territory' 在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。
- [Microsoft][SQL Native Client][SQL Server]Statement 'Serv
请指教