Advertisement
GerexD

sql

Nov 20th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. select t1.Name, t1.Osszmennyiseg, count(t2.RaktarakSzama1) as RaktarakSzama
  2. from
  3. (select distinct ProductSubcategory.Name,
  4. SUM(ProductInventory.Quantity) as Osszmennyiseg
  5. --ROW_NUMBER() OVER(PARTITION BY ProductSubcategory.Name ORDER BY ProductInventory.LocationID DESC) as RaktarakSzama
  6. from Production.ProductSubcategory
  7. join Production.ProductCategory on ProductCategory.ProductCategoryID = ProductSubcategory.ProductCategoryID
  8. join Production.Product on ProductSubcategory.ProductSubcategoryID = Product.ProductSubcategoryID
  9. join Production.ProductInventory on ProductInventory.ProductID = Product.ProductID
  10. group by ProductSubcategory.Name) t1
  11. join (select ProductSubcategory.Name,
  12. --COUNT(ProductSubcategory.Name) as RaktarakSzama
  13. ROW_NUMBER() OVER(PARTITION BY ProductSubcategory.Name ORDER BY ProductInventory.LocationID DESC) as RaktarakSzama1
  14. from Production.ProductSubcategory
  15. join Production.ProductCategory on ProductCategory.ProductCategoryID = ProductSubcategory.ProductCategoryID
  16. join Production.Product on ProductSubcategory.ProductSubcategoryID = Product.ProductSubcategoryID
  17. join Production.ProductInventory on ProductInventory.ProductID = Product.ProductID
  18. group by ProductSubcategory.Name,ProductInventory.LocationID ) t2
  19. on t1.Name = t2.Name
  20. group by t1.Name, t1.Osszmennyiseg
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement