Group By Cube
Tüm verilerin gruplanmasına ilave olarak verilerin toplamlarını göstermenizi sağlamaktadır.
select isnull(Cast(ProductID as nvarchar(50)),'Toplam') as ProducId, sum(StandardCost) as Total from [Production].[ProductCostHistory] where ProductID in (707,708) Group by cube (ProductID)
ProducId | Total |
707 | 38,9923 |
708 | 38,9923 |
Toplam | 77,9846 |
Group By Rollup
Gruplama yaptığımız veri üzerinde hem ara toplam hemde genel toplam almamızı sağlayan operatördür.
Select isnull(i.Shelf, 'Genel') as Shelf, isnull(p.Name,isnull(i.Shelf, 'Genel') + ' Toplam') as Name, Sum(i.Quantity) as Total From Production.ProductInventory i inner join Production.Product p On i.ProductID = p.ProductID Where p.name like 'B%' group by rollup (i.Shelf, p.Name)
Shelf | Name | Total |
A | BB Ball Bearing | 909 |
A | Bearing Ball | 791 |
A | Blade | 532 |
A | A Toplam | 2232 |
B | BB Ball Bearing | 443 |
B | Bearing Ball | 318 |
B | Blade | 829 |
B | B Toplam | 1590 |
N/A | Bike Wash – Dissolver | 36 |
N/A | N/A Toplam | 36 |
Genel | Genel Toplam | 3858 |