Expert T-SQL Window Functions in SQL Server by Kathi Kellenberger & Clayton Groom
Author:Kathi Kellenberger & Clayton Groom
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
Run Listing 5-2 to see an example.
Listing 5-2. Calculating Moving Averages and Sums
--5-2.1 Three month sum and average for products qty sold
SELECT MONTH(SOH.OrderDate) AS OrderMonth, SOD.ProductID, SUM(SOD.OrderQty) AS QtySold,
SUM(SUM(SOD.OrderQty))
OVER(PARTITION BY SOD.ProductID ORDER BY MONTH(SOH.OrderDate)
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS ThreeMonthSum,
AVG(SUM(SOD.OrderQty))
OVER(PARTITION BY SOD.ProductID ORDER BY MONTH(SOH.OrderDate)
ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS ThreeMonthAvg
FROM Sales.SalesOrderHeader AS SOH
JOIN Sales.SalesOrderDetail AS SOD ON SOH.SalesOrderID = SOD.SalesOrderID
JOIN Production.Product AS P ON SOD.ProductID = P.ProductID
WHERE OrderDate >= '2013-01-01' AND OrderDate < '2014-01-01'
GROUP BY MONTH(SOH.OrderDate), SOD.ProductID;
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Ada | Ajax |
Assembly Language Programming | Borland Delphi |
C & C++ | C# |
CSS | Compiler Design |
Compilers | DHTML |
Debugging | Delphi |
Fortran | Java |
Lisp | Perl |
Prolog | Python |
RPG | Ruby |
Swift | Visual Basic |
XHTML | XML |
XSL |
Hello! Python by Anthony Briggs(9870)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9760)
The Mikado Method by Ola Ellnestam Daniel Brolund(9751)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8261)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7748)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7744)
Grails in Action by Glen Smith Peter Ledbrook(7670)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7520)
Windows APT Warfare by Sheng-Hao Ma(6511)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6381)
Layered Design for Ruby on Rails Applications by Vladimir Dementyev(6256)
Blueprints Visual Scripting for Unreal Engine 5 - Third Edition by Marcos Romero & Brenden Sewell(6129)
Kotlin in Action by Dmitry Jemerov(5022)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4300)
Functional Programming in JavaScript by Mantyla Dan(4022)
Solidity Programming Essentials by Ritesh Modi(3845)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3620)
Unity 3D Game Development by Anthony Davis & Travis Baptiste & Russell Craig & Ryan Stunkel(3571)
The Ultimate iOS Interview Playbook by Avi Tsadok(3539)
