SELECT products.name
, products.size
, products.category
, count(distinct orders.id) as "numOrders"
, rank() over (partition by products.category order by count(distinct orders.id) DESC) as "orderRank"
FROM products
JOIN order_items
ON products.SKU = order_items.SKU
JOIN orders
ON order_items.orderId = orders.id
GROUP BY 1, 2, 3