Docs

ORDER BY

Last updated: 27 Oct 2026

ORDER BY sorts the rows by one or more columns of the result. DESC sorts largest first, and ASC, the default, smallest first.

ORDER BY <column> [ASC | DESC], …

You can sort by a metric, by a calculation's name, by a comparison column such as room_revenue__stly, or by a dimension the query groups by.

Without ORDER BY, a time series runs oldest first and anything else sorts by its first metric, largest first. Rows that tie are sorted by the grouped dimensions, so the same query always returns its rows in the same order.

Best-selling activities first

FROM activities
  SHOW tickets_sold, activity_revenue
  DURING last_month
  GROUP BY activity
  ORDER BY tickets_sold DESC

Room types in alphabetical order

FROM rooms
  SHOW occupancy, adr
  DURING last_month
  GROUP BY room_type
  ORDER BY room_type

Biggest growth against last year

FROM rooms
  SHOW room_revenue
  DURING last_month
  GROUP BY channel
  COMPARE TO stly
  WITH PERCENT_CHANGE
  ORDER BY room_revenue__stly_pct_change DESC

Several columns

FROM revenue
  SHOW net_revenue
  DURING last_quarter
  GROUP BY month, revenue_category
  ORDER BY month, net_revenue DESC