Try .NET /elinq/
Powered by Try .NET

SQL Server CUBE and ROLLUP

Please go over GROUPING SETS first.

SQL Server CUBE examples

var query = DbContext.Set<SalesSummary>()
                .Query((SalesSummary alias) =>
                {
                    var salesSummary = GetSalesSummaryTable();

                    var result = SELECT<SalesSummary>(salesSummary.Brand.@as(alias.Brand),
                        salesSummary.Category.@as(alias.Category),
                        SUM(salesSummary.Sales).@as(alias.Sales));

                    FROM(salesSummary);
                    GROUP(BY(CUBE(salesSummary.Brand, salesSummary.Category)));

                    return result;
                });

foreach (var salesSummary in query.Take(3))
    Console.WriteLine((salesSummary.Brand, salesSummary.Category, salesSummary.Sales));

SQL Server ROLLUP examples

Replace CUBE with ROLLUP above and run!


< BACK | HOME