Averages are pulled around by a few large values; the median is not. SQL's standard way to get it's an ordered-set aggregate:
SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY total) AS median_total
FROM orders;
PERCENTILE_CONT interpolates: with an even number of rows, the median is halfway between the two middle values. PERCENTILE_DISC returns an actual value from the data (the lower of the two middle ones). Use 0.25 and 0.75 for quartiles, 0.9 for the 90th percentile. This works in PostgreSQL, Oracle, Snowflake and here; DuckDB and Snowflake also have MEDIAN(x). MySQL has none of these, and SQL Server only has them as window functions.
NTILE(4) OVER (ORDER BY spent) splits rows into four groups as equal in size as possible and numbers them 1 to 4. It's how you make quartiles of customers. When the count doesn't divide evenly, the first groups get one extra row.