title: Multiple subtotals - Rollup order of fields
body: <p>I am trying to run a query that aggregates data, groups the results by  several different fields, and extract <strong>all</strong> relevant "SubTotal" permutations. (similar to CUBE() in MSSQL)</p>
  
  <p>When Using <code>Group By Rollup()</code>, I get only permutations according to the order of the <code>Group By</code> fields in the <code>Rollup</code> function.
  For example the query below (runs on a public dataset), it returns subtotal by year, or by year and month, or by year, month and medallion... but it doesn't subtotal by medallion.</p>
  
  <pre><code>SELECT
    trip_year,
    trip_month,
    medallion,
    SUM(trip_count) AS Sum_trip_count
  FROM
    [nyc-tlc:yellow.Trips_ByMonth_ByMedallion]
  WHERE
    medallion IN ("2R76",    "8J82",    "3B85",    "4L79",    "5D59",    "6H75",    "7P60",    "8V48",    "1H12",    "2C69",    "2F38",    "5Y86",    "5j90",    "8A75",    "8V41",    "9J24",    "9J55",    "1E13",    "1J82")
  GROUP BY
    ROLLUP(trip_year,
      trip_month,
      medallion)
  </code></pre>
  
  <p>My question is:
  What should I do in order to get all different permutations of "Sub Totals" in a single query results.</p>
  
  <p>Already tried: Union with similar query but with different order, it works, but not elegant (it would require too many unions).
  Thanks</p>