表1:商品表

表2:商品售卖表

需求:算出商品的平均点击率、平均销售、商品受欢迎度

1.使用inner join查出每件商品的点击率和销售额度

select a.ptype, a.pname, a.pview, ifnull(b.sales, 0) as selas
from test a
left join test_sell b on a.pid = b.id
order by a.ptype desc, a.pview DESC

结果:

2.查出每个商品类的平均点击率

 select ptype, sum(pview) / count(*) as avg_pview from test group by ptype

3.查出每个商品类的平均销售额度

     select ptype,round(sum(selas) / count(*), 0) as avg_sales
from (select a.ptype, a.pname, a.pview, ifnull(b.sales, 0) as selas
from test a
left join test_sell b on a.pid = b.id
order by a.ptype desc, a.pview DESC) a
where a.selas > 0
group by ptype

 

总sql:

select a.ptype,pname,pview,avg_pview,(pview/avg_pview)*0.3,selas,avg_sales,(selas/avg_sales)*0.7,(pview/avg_pview)*0.3+(selas/avg_sales)*0.7
from (select a.ptype, a.pname, a.pview, ifnull(b.sales, 0) as selas
from test a
left join test_sell b on a.pid = b.id
order by a.ptype desc, a.pview DESC) a,
(
select ptype, sum(pview) / count(*) as avg_pview from test group by ptype) b,
(select ptype,round(sum(selas) / count(*), 1) as avg_sales
from (select a.ptype, a.pname, a.pview, ifnull(b.sales, 0) as selas
from test a
left join test_sell b on a.pid = b.id
order by a.ptype desc, a.pview DESC) a
where a.selas > 0
group by ptype) c where a.ptype = b.ptype
and b.ptype = c.ptype order by a.ptype;

总结:通过点击率和销售量的权重,得出商品的欢迎度,

最新文章

  1. android 开发 gradle 自己会容易混淆的东西
  2. The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION'
  3. consul 模板配置内容的参数说明
  4. java中的日期操作Calendar和Date
  5. NYOJ 16 矩形嵌套(经典动态规划)
  6. VMware Workstation不可恢复的错误:(vmui)
  7. css公共样式,初始化
  8. 百度地图LBS开放平台AK一直没有用
  9. ECSHOP 订单状态 记录
  10. Oracle----date
  11. 华为 2015 机试 输出:数字后面的连续出现的(2个或多个)相同字符(数字或者字符),删去一个,非数字后面的不要删除,例如,对应输出为:33aabb55pin。
  12. 提示框的优化之自定义Toast组件之(三)Toast组件优化
  13. 使用Groovy进行依赖注入
  14. VMware GSX Server 3.2.1 Build 19281免费下载
  15. linux系统日志查看
  16. [原创]基于Zynq AXI-Bram Standalone & Linux 例程
  17. vue-cli3使用webpack-spritesmith配置雪碧图
  18. 1-JRE与JDK等知识
  19. [sql]mysql5.6cmake安装/mysql5.7二进制安装
  20. Java设计模式の单利模式

热门文章

  1. No module named 'dateutil'
  2. μC/OS-II中使用软件定时器
  3. mysql之左连接、右连接、内连接、全连接、等值连接、交叉连接等
  4. LGOJ3327 【SDOI2015】约数个数和
  5. Python练习四-浅拷贝&深拷贝
  6. VSTO外接程序项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【C#版】
  7. 将java list转换为js的数组
  8. [LC] 380. Insert Delete GetRandom O(1)
  9. mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法
  10. program files 和 program files 86