這裏是我的查詢 - 通過SAP查詢工具創建:SQL錯誤選擇列表中無效,因爲它不是在聚合函數或GROUP包含BY子句
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領域:
- [微軟] [SQL本機客戶端] [SQL服務器]列 「ASAP.dbo.OCRD.Territory」是在選擇列表中,因爲它無效是 不包含在聚合函數或GROUP BY子句中。
- [微軟] [SQL本機客戶端] [SQL服務器]聲明「SERV
請告知
你發佈的sql很好。這個錯誤可能來自大事務中的其他事務,這是(?)的一部分。如果您突出顯示您的交易的這一部分並運行它,您是否仍然遇到錯誤? – Chains