Mysql
 sql >> Base de données >  >> RDS >> Mysql

Comment faire deux SUM MySQL en fonction de critères différents

Ce que vous semblez rechercher est la partie GROUP BY d'un SELECT, comme ceci :

SELECT DISTINCT company_report.*, floor(sum(variable_value)) as totalSum
FROM company_report
JOIN company        ON company_report.special_id = company.special_id 
JOIN users          ON company.id = users.company_id 
JOIN club           ON users.id = club.users_id
JOIN club_offer     ON club.id = club_offer.club_id
JOIN club_offer_cpv ON club_offer.id = club_offer_id 
                    AND club_offer_cpv.cpv_id LIKE '66%' 
                    AND company_report.variable_code IN ('AOP 201','AOP 605')
                    AND company_report.report_year = 2013
GROUP BY company_report.variable_code                    

C'est ça ?