Hello guys!
I found that the "with rollup" option used with group by is very useful. But it does not behave with "order by" clause.
Is there any way to order by my way?
Output:Code:SELECT COALESCE (name, 'GRAND TOTAL') AS name, tot FROM ( SELECT name, COUNT(*) AS tot FROM tbl_p ) GROUP BY name WITH ROLLUP ) Q ORDER BY CASE WHEN name = 'GRAND TOTAL' THEN 1 ELSE 0 END;
I need this output:Code:+------------------------------+--------+ | name | tot | +------------------------------+--------+ | SEAN DUBOIS | 3 | | SEAN MAXWELL | 2 | | GRAND TOTAL | 39 | | DILLINGER BOY | 12 | | DILLINGER GIRL | 22 | +------------------------------+--------+
Could you please help?Code:+------------------------------+--------+ | name | tot | +------------------------------+--------+ | GRAND TOTAL | 39 | | DILLINGER BOY | 12 | | DILLINGER GIRL | 22 | | SEAN DUBOIS | 3 | | SEAN MAXWELL | 2 | +------------------------------+--------+
Thanks you very much for your help.



Reply With Quote






Bookmarks