SELECT A.PRODUCT_CODE, SUM(A.PRICE * B.SALES_AMOUNT) AS SALES FROM PRODUCT A LEFT JOIN OFFLINE_SALE B ON A.PRODUCT_ID = B.PRODUCT_ID GROUP BY PRODUCT_CODE ORDER BY SALE DESC, A.PRODUCT_CODE