Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 6.2
- SELECT DISTINCT CustomerID Klient,
- YEAR(OrderDate) Rok,
- COUNT(SalesOrderID) OVER (PARTITION BY (CustomerID) ORDER BY Year(OrderDate)) AS 'Liczba zamówień'
- FROM Sales.SalesOrderHeader
- ORDER BY 1, 3, 2;
- -- 6.3
- SELECT SalesPersonID,
- Rok,
- Miesiac,
- "W miesiącu",
- "W roku",
- "W roku narastająco",
- 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"
- FROM ( SELECT DISTINCT SalesPersonID,
- YEAR(OrderDate) AS Rok,
- MONTH(OrderDate) AS Miesiac,
- COUNT(SalesOrderID) OVER (PARTITION BY SalesPersonID, YEAR(OrderDate), MONTH(OrderDate)) AS "W miesiącu",
- COUNT(SalesOrderID) OVER (PARTITION BY SalesPersonID, YEAR(OrderDate)) AS "W roku",
- COUNT(SalesOrderID) OVER (PARTITION BY SalesPersonID, YEAR(OrderDate) ORDER BY MONTH(OrderDate)) AS "W roku narastająco"
- FROM Sales.SalesOrderHeader
- WHERE SalesPersonID IS NOT NULL
- ) sourceTable
- ORDER BY 1, 2, 3;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement