分別把 計算各自的 一、點擊量/點擊量均值 二、銷售量/銷售量均值 二者相加,能夠獲得一個簡單評分 又有問題了,豬肉的評分不該該比五花肉多。 所以咱們要加入簡單的權重,譬如點擊量評分佔30%。銷售量評分佔70%
select p_type,p_name, (p_view/view_avg)*0.3+(sales/sales_avg)*0.7 from ( select a.*,b.sales_avg,c. view_avg from (select p_type,a.p_name,a.p_view, IFNULL(b.p_sales,0) as sales from products a LEFT JOIN products_sales b on a.p_id=b.p_id GROUP BY a.p_type,a.p_name order by a.p_type desc, a.p_view desc ) a , ( select p_type,round(sum(sales)/count(*),0) as sales_avg from ( select p_type, a.p_name,a.p_view, IFNULL(b.p_sales,0) as sales from products a LEFT JOIN products_sales b on a.p_id=b.p_id GROUP BY a.p_type,a.p_name order by a.p_type desc, a.p_view desc ) c where c.sales>0 GROUP BY p_type ) b, (select p_type,round(sum(p_view)/count(*),0) as view_avg from products GROUP BY p_type ) c where a.p_type=b.p_type and a.p_type=c.p_type ) aa