Fix get_market_value_total to use raw-sql, windowing/grouping/magic