Two left joins gives me untrue data(double data?) with MySQL

后端 未结 3 1386
梦谈多话
梦谈多话 2021-01-26 06:56

This is my query:

SELECT `products`.*, SUM(orders.total_count) AS revenue,
    SUM(orders.quantity) AS qty, ROUND(AVG(product_reviews.stars)) as avg_stars 
FROM          


        
3条回答
  •  耶瑟儿~
    2021-01-26 07:43

    Its not easy to solve this without seeing your table schemas, I would suggest you look at your Aggregations and Group By statements first, then look at your column default values, how are you handling empty values, also look at DISTINCT in the Aggregation functions.

    If all else fails and a "optimized" solution is not vital and your data volumes are low do a Sub Select only on the tables for which you require the values, within the Sub Select on 1 table you have a much narrower row scope and it will yield the correct result.

    I would suggest that you supply your table schemas here.

提交回复
热议问题