• Sean Lange (9/6/2012)


    ...

    This query will produce the same results:

    SELECT

    COALESCE ([MAT], 'Tot') AS [MAT],

    [DVD],

    SUM ([SALES])

    FROM

    TestTable

    GROUP BY

    (MAT),

    [DVD] --with rollup

    ORDER BY

    [DVD] DESC

    ...

    Try to add one more data row:

    INSERT INTO [dbo].[TestTable] ([MAT], [DVD], [SALES]) VALUES (N'WAS', N'L12', N'3');

    To ensure that 'Tot' record is placed as the last per DVD, you should treat it separately eg.

    ORDER BY [DVD] DESC, CASE WHEN MAT = 'Tot' THEN 1 ELSE 0 END, MAT

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]