SELECT os, browser, sum(page_views) FROM test.ga_tb2 GROUP BY GROUPING SETS ((os, browser), ()) -- ここ、微妙に変えた HAVING sum(page_views) > 20 ORDER BY os, browser; os | browser | sum -----------+-------------------+------- Android | Android Browser | 254 Android | Chrome | 472 Android | Firefox | 232 Android | Opera | 73 iOS | Chrome | 41 iOS | Safari | 625 iOS | Safari (in-app) | 37 Linux | Chrome | 301 Linux | Firefox | 692 Macintosh | Chrome | 1392 Macintosh | Firefox | 409 Macintosh | Safari | 897 Windows | Chrome | 15377 Windows | Firefox | 6492 Windows | Internet Explorer | 12264 Windows | Iron | 84 Windows | Opera | 359 <- ここまで普通の GROUP BY と同じ | | 40145 <- これが総計行 (18 rows)