Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. -- 6.2
  2. SELECT DISTINCT CustomerID Klient,
  3. YEAR(OrderDate) Rok,
  4. COUNT(SalesOrderID) OVER (PARTITION BY (CustomerID) ORDER BY Year(OrderDate)) AS 'Liczba zamówień'
  5. FROM Sales.SalesOrderHeader
  6. ORDER BY 1, 3, 2;
  7.  
  8. -- 6.3
  9. SELECT SalesPersonID,
  10. Rok,
  11. Miesiac,
  12. "W miesiącu",
  13. "W roku",
  14. "W roku narastająco",
  15. SUM("W miesiącu") OVER (PARTITION BY SalesPersonID, Rok ORDER BY Miesiac ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS "Obecny i poprzedni miesiąc"
  16. FROM ( SELECT DISTINCT SalesPersonID,
  17. YEAR(OrderDate) AS Rok,
  18. MONTH(OrderDate) AS Miesiac,
  19. COUNT(SalesOrderID) OVER (PARTITION BY SalesPersonID, YEAR(OrderDate), MONTH(OrderDate)) AS "W miesiącu",
  20. COUNT(SalesOrderID) OVER (PARTITION BY SalesPersonID, YEAR(OrderDate)) AS "W roku",
  21. COUNT(SalesOrderID) OVER (PARTITION BY SalesPersonID, YEAR(OrderDate) ORDER BY MONTH(OrderDate)) AS "W roku narastająco"
  22. FROM Sales.SalesOrderHeader
  23. WHERE SalesPersonID IS NOT NULL
  24. ) sourceTable
  25. ORDER BY 1, 2, 3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement