Pure SQL implementation of small algorithm (auxiliary decision) _ Calculate product score, timely replenishment

Source: Internet
Author: User

respectively, the calculation of their respective 1, click/Click Average value 2, sales/sales mean the sum of the two, you can get a simple score and problems, pork should not score more than pork. So we have to add a simple weight, such as a click score of 30%. Sales score was 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 bon a.p_id=b.p_idgroup 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 bon a.p_id=b.p_idgroup by  a.p_type,a.p_name  order by a.p_type desc, a.p_view desc )  cwhere c.sales>0group  by p_type) b, (SELect p_type,round (SUM (p_view)/count (*), 0)  as view_avg from products GROUP  by p_type ) cwhere a.p_type=b.p_type  and a.p_type=c.p_type )  aa


Pure SQL implementation of small algorithm (auxiliary decision) _ Calculate product score, timely replenishment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.