Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Wie man zwei MySQL-SUMs basierend auf unterschiedlichen Kriterien erstellt

Was Sie zu suchen scheinen, ist der GROUP BY-Teil eines SELECT, wie folgt:

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                    

Ist es das?