Mysql
 sql >> Database >  >> RDS >> Mysql

Come sommare una singola colonna in base al raggruppamento in MySQL

Puoi provare questaSqlFiddle Demo

SELECT
    BrandMaster.BID,          
    IFNULL(SUM(Sales.Amount),0) AS SumAmount
FROM BrandMaster 
    LEFT JOIN Sales ON ( BrandMaster.BID=Sales.BID )
GROUP BY
    BrandMaster.BID
ORDER BY 
    BrandMaster.BID,
    Sales.SNo