sql--测试商品的重要度,是否需要及时补货
2024-09-07 08:08:54
表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;
总结:通过点击率和销售量的权重,得出商品的欢迎度,
最新文章
- android 开发 gradle 自己会容易混淆的东西
- The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION'
- consul 模板配置内容的参数说明
- java中的日期操作Calendar和Date
- NYOJ 16 矩形嵌套(经典动态规划)
- VMware Workstation不可恢复的错误:(vmui)
- css公共样式,初始化
- 百度地图LBS开放平台AK一直没有用
- ECSHOP 订单状态 记录
- Oracle----date
- 华为 2015 机试 输出:数字后面的连续出现的(2个或多个)相同字符(数字或者字符),删去一个,非数字后面的不要删除,例如,对应输出为:33aabb55pin。
- 提示框的优化之自定义Toast组件之(三)Toast组件优化
- 使用Groovy进行依赖注入
- VMware GSX Server 3.2.1 Build 19281免费下载
- linux系统日志查看
- [原创]基于Zynq AXI-Bram Standalone &; Linux 例程
- vue-cli3使用webpack-spritesmith配置雪碧图
- 1-JRE与JDK等知识
- [sql]mysql5.6cmake安装/mysql5.7二进制安装
- Java设计模式の单利模式
热门文章
- No module named 'dateutil'
- μC/OS-II中使用软件定时器
- mysql之左连接、右连接、内连接、全连接、等值连接、交叉连接等
- LGOJ3327 【SDOI2015】约数个数和
- Python练习四-浅拷贝&;深拷贝
- VSTO外接程序项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【C#版】
- 将java list转换为js的数组
- [LC] 380. Insert Delete GetRandom O(1)
- mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法
- program files 和 program files 86