Hot answers tagged

3

Explanation First all the JOINing is done. This inflates the number of rows. Then you do a GROUP BY and SUM. Hence, the "unbelievably large numbers". Solution 1 A solution is usually to do the GROUP BY and SUM over just one table. If that can't be done, then find the ids for that one table, dedup them (via DISTINCT or GROUP BY), then do the grouping ...


1

Another way you can do this is by summing each criterion by a CASE statement: SELECT market_id, SUM(CASE WHEN a = 1 THEN total_purchase END) AS acc_purchase, SUM(CASE WHEN a = 1 THEN total_profit END) AS acc_profit, SUM(CASE WHEN a = 1 THEN company_profit END) AS acc_company_profit, ((SUM(CASE WHEN b = 1 THEN total_purchase END) ...


1

The problems got removed, when i swapped the my.cnf file, with a highly simplified version of it, which was earlier present in a machine, having MySQL 5.6. So possibly the issue was with my.cnf file. # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html [mysqld] init-connect='SET ...



Only top voted, non community-wiki answers of a minimum length are eligible