1

I have s set of data which I want to group with GROUPING SETS / ROLLUP. There is a fiddle at: https://dbfiddle.uk/XB0nOBWb .

SELECT initial, data, count(*)
FROM test
GROUP BY ROLLUP(initial,data);

Apparently MariaDB doesn’t have a grouping() function which gives the grouping level. I would have used that in other DBMSs (such as PostgreSQL) to sort in the right order:

SELECT initial, data, count(*)
FROM test
GROUP BY initial,data WITH ROLLUP
ORDER BY grouping(initial),initial,grouping(data),data;

How would I sort this in MariaDB?

I note that in the fiddle (and in my own version) the result is sorted correctly, but I don’t know whether that’s reliable.

Manngo
  • 14,066
  • 10
  • 88
  • 110

0 Answers0