先把order表聚一下在连接,否则同个款型有多个记录
SELECT style_id,
round(sum(sales_num)/
(sum(inventory)-sum(sales_num))*100,2),
round(100*sum(GMV)/sum(tag_price*(inventory)),2)
from
product_tb left JOIN
(select item_id,sum(sales_num) as sales_num,
sum(sales_price) as GMV from sales_tb
where month(sales_date)=11
GROUP by item_id) tmp
using(item_id)
GROUP BY style_id