Su pregunta parece ser sobre ordenar los resultados. La solución es usar funciones de ventana en ORDER BY
:
SELECT lot, defect, SUM(quantity)
FROM table
GROUP BY lot, defect
ORDER BY SUM(SUM(quantity)) OVER (PARTITION BY lot) DESC,
lot, SUM(quantity) DESC, defect;