SELECT user_id, SUM(order_amount) AS total_amount FROM orders GROUP BY user_id;
SELECT u.name, o.total_amount FROM users u JOIN ( SELECT user_id, SUM(order_amount) AS total_amount FROM orders GROUP BY user_id ) o ON u.id = o.user_id;