近いですが、各営業担当者が過去数年間に達成した売上を実際に見ていません...表SalesQuota
で見ている列は、通常、目標としてSalesPerson
定義された数値です。その年 - これは実際に行われたすべての売上の合計ではありません。
私はこのようなことを試してみます:
-- determine the SUM of all sales, for all salespeople, since Jan 1, 2008
-- SUM the total of all sales (their TotalDue value) from the SalesOrderHeader table
;WITH SalesPerPerson AS
(
SELECT
sp.BusinessEntityID,
TotalSales = SUM(soh.TotalDue) -- SUM of all sales total amounts
FROM
Sales.SalesOrderHeader soh
INNER JOIN
Sales.SalesPerson sp ON soh.SalesPersonID = sp.BusinessEntityID
WHERE
soh.OrderDate >= '20080101' -- on all sales since Jan 1, 2008
GROUP BY
sp.BusinessEntityID
)
-- from that CTE, select the sales people who have had less than 100'000$ in
-- sales since Jan 1, 2008, and display those. Show LoginID and first and
-- last name (just for information purposes)
SELECT
p.FirstName, p.LAstName,
e.LoginID,
spp.*
FROM
SalesPerPerson spp
INNER JOIN
Person.Person p ON spp.BusinessEntityID = p.BusinessEntityID
INNER JOIN
HumanResources.Employee e ON p.BusinessEntityID = e.BusinessEntityID
WHERE
TotalSales < 100000.0
したがって、本当に のみが必要な場合はLoginID
、テーブルへの JOIN を省略して、出力から列Person.Person
を削除できます。p.FirstName, p.LastName