Oct-17-2019, 11:13 PM
All,
I would like to pivot a data frame similar to the following SQL operation. Any help/guidance is appreciated:
I would like to pivot a data frame similar to the following SQL operation. Any help/guidance is appreciated:
# SQL Code - https://www.sqlshack.com/static-and-dynamic-sql-pivot-and-unpivot-relational-operator-overview/ SELECT * FROM ( SELECT YEAR(SOH.OrderDate) as SalesYear, SOH.SubTotal as TotalSales FROM sales.SalesOrderHeader SOH JOIN sales.SalesOrderDetail SOD ON SOH.SalesOrderId = SOD.SalesOrderId ) AS Sales PIVOT (SUM(TotalSales) FOR SalesYear IN ([2011],[2012],[2013],[2014])) as PVT