WITH temp AS(
SELECT a.brand_id,b.brand_name,a.return_status,c.customer_satisfaction_score
FROM sales_orders AS a
INNER JOIN brand_info AS b ON a.brand_id = b.brand_id
INNER JOIN customer_feedback AS c ON a.order_id = c.order_id
WHERE MONTH(a.order_date) = 7
)
SELECT brand_id,brand_name,
round(avg(return_status),2) return_rate_July_2024,
round(avg(customer_satisfaction_score),2) average_customer_satisfaction_score
FROM temp
GROUP BY brand_id,brand_name
ORDER BY brand_id ASC
以sales_order为表连结的主表,因为剩下两个表没办法直接相连,我第一遍就犯了这个错误,剩下的就简单了,GROUP BY 或者窗口函数都可以

京公网安备 11010502036488号