I'm not entirely sure where it's coming from - almost looks like a category page query but the ORDER BY SUM(Quantity) DESC is throwing me off.
Any thoughts?
SELECT P.ProductId AS PrimaryKey FROM ac_Products P INNER JOIN ac_OrderItems OI ON P.ProductId = OI.ProductId WHERE P.VisibilityId = ? AND P.ProductId IN (SELECT CatalogNodeId FROM ac_CatalogNodes WHERE CatalogNodeTypeId = ? AND CategoryId IN (SELECT CategoryId FROM ac_Categories WHERE CategoryId IN (SELECT CategoryId FROM ac_CategoryParents WHERE ParentId = @p0))) GROUP BY P.ProductId ORDER BY SUM(Quantity) DESC