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

Come eseguire due MySQL SUM in base a criteri diversi

Quello che sembra che tu stia cercando è la parte GROUP BY di una SELECT, come questa:

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                    

È così?