Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Select A.CompanyName, Year(D.OrderDate), MONTH(D.OrderDate),Sum(C.UnitPrice * C.Quantity * (1-C.Discount)) as 'Przychod'
- From Suppliers as A
- INNER JOIN Products as B
- ON A.SupplierID = B.SupplierID
- INNER JOIN [Order Details] as C
- ON B.ProductID = C.ProductID
- INNER JOIN ORDERS as D
- ON D.OrderID = C.OrderID
- GROUP BY A.CompanyName, Year(D.OrderDate) ,MONTH(D.OrderDate)
- HAVING Sum(C.UnitPrice * C.Quantity * (1-C.Discount)) > (
- SELECT SUM(E.UnitPrice * E.Quantity * (1-E.Discount)) / (Select Count(A1.CompanyName)
- From Suppliers as A1
- INNER JOIN Products as B1
- ON A1.SupplierID = B1.SupplierID
- INNER JOIN [Order Details] as C1
- ON B1.ProductID = C1.ProductID
- INNER JOIN ORDERS as D1
- ON D1.OrderID = C1.OrderID
- WHERE
- Year(D.OrderDate) = YEAR(D1.OrderDate)
- AND MONTH(D.OrderDate) = MONTH(D1.OrderDate)
- )
- FROM [Order Details] as E
- INNER JOIN Orders as F
- ON F.OrderID = E.OrderID
- WHERE
- MONTH(F.OrderDate) = MONTH(D.OrderDate)
- AND YEAR(F.OrderDate) = YEAR(D.OrderDate)
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement