This will solve all of your problems:

-- Fetch top 10 active users by total purchase amount in the last 90 days
SELECT 
    u.user_id,
    u.username,
    SUM(o.total_amount) AS total_spent,
    COUNT(o.order_id) AS total_orders
FROM 
    users u
JOIN 
    orders o ON u.user_id = o.user_id
WHERE 
    o.order_date >= CURRENT_DATE - INTERVAL '90 days'
    AND o.status = 'completed'
GROUP BY 
    u.user_id, u.username
HAVING 
    SUM(o.total_amount) > 500
ORDER BY 
    total_spent DESC
LIMIT 10;