Sales.vSalesPersonSalesByFiscalYears
Documentation | AdventureWorks |
Schema | Sales |
Name | vSalesPersonSalesByFiscalYears |
Module | Sales |
Uses PIVOT to return aggregated sales information for each sales representative.
Columns
Key | Name | Data type | Null | Attributes | References | Description | ||
---|---|---|---|---|---|---|---|---|
1 | SalesPersonID | int | ||||||
2 | FullName | nvarchar(152) | ||||||
3 | JobTitle | nvarchar(50) | ||||||
4 | SalesTerritory | nvarchar(50) | ||||||
5 | 2002 | money | ||||||
6 | 2003 | money | ||||||
7 | 2004 | money |
Uses
Name |
---|
Sales.vSalesPersonSalesByFiscalYears
|
Script
CREATE VIEW [Sales].[vSalesPersonSalesByFiscalYears] AS SELECT pvt.[SalesPersonID] ,pvt.[FullName] ,pvt.[JobTitle] ,pvt.[SalesTerritory] ,pvt.[2002] ,pvt.[2003] ,pvt.[2004] FROM (SELECT soh.[SalesPersonID] ,p.[FirstName] + ' ' + COALESCE(p.[MiddleName], '') + ' ' + p.[LastName] AS [FullName] ,e.[JobTitle] ,st.[Name] AS [SalesTerritory] ,soh.[SubTotal] ,YEAR(DATEADD(m, 6, soh.[OrderDate])) AS [FiscalYear] FROM [Sales].[SalesPerson] sp INNER JOIN [Sales].[SalesOrderHeader] soh ON sp.[BusinessEntityID] = soh.[SalesPersonID] INNER JOIN [Sales].[SalesTerritory] st ON sp.[TerritoryID] = st.[TerritoryID] INNER JOIN [HumanResources].[Employee] e ON soh.[SalesPersonID] = e.[BusinessEntityID] INNER JOIN [Person].[Person] p ON p.[BusinessEntityID] = sp.[BusinessEntityID] ) AS soh PIVOT ( SUM([SubTotal]) FOR [FiscalYear] IN ([2002], [2003], [2004]) ) AS pvt; |
Exported: 2019-02-04 23:13, Last imported: 2018-03-07 11:56