我使用SQL管理器创建了一个请求:
SELECT
CONCAT(LastName,' ', FirstName) AS [Nom du vendeur],
SalesPersonID,
DATEPART(YYYY, [OrderDate]) AS [Annee],
FORMAT(SUM(soh.SubTotal), '#,#00.') AS [Ventes]
FROM
Sales.SalesOrderHeader AS soh
INNER JOIN
Person.Person AS pp ON soh.SalesPersonID = pp.BusinessEntityID
WHERE
pp.PersonType = 'SP'
AND soh.OnlineOrderFlag = '0'
AND OrderDate NOT BETWEEN CONVERT(DATETIME, '01/01/2011', 101) AND CONVERT(DATETIME, '12/31/2011', 101)
GROUP BY
SubTotal, OrderDate, SalesPersonID,LastName, FirstName
ORDER BY
[Annee], [Nom du vendeur]
这是我的输出:
https://i.stack.imgur.com/00jjA.png
[您可以在代表销售列的[ventes]
列中看到,根据ID号和名称,销售并不能全部累加,而我在选择中使用了SUM()
函数。任何想法我的代码有什么问题吗?