sql server 2016 cte

Solutions on MaxInterview for sql server 2016 cte by the best coders in the world

showing results for - "sql server 2016 cte"
Ashley
17 Oct 2016
1-- Define the CTE expression name and column list.  
2WITH Sales_CTE (SalesPersonID, SalesOrderID, SalesYear)  
3AS  
4-- Define the CTE query.  
5(  
6    SELECT SalesPersonID, SalesOrderID, YEAR(OrderDate) AS SalesYear  
7    FROM Sales.SalesOrderHeader  
8    WHERE SalesPersonID IS NOT NULL  
9)  
10-- Define the outer query referencing the CTE name.  
11SELECT SalesPersonID, COUNT(SalesOrderID) AS TotalSales, SalesYear  
12FROM Sales_CTE  
13GROUP BY SalesYear, SalesPersonID  
14ORDER BY SalesPersonID, SalesYear;  
15
similar questions
queries leading to this page
sql server 2016 cte