之前用版主的查询代码可以生成日销量数据,但是速度越来越慢,要好几分钟才能查出来,现在想直接生成,直接调用,速度上有保障,数据也可以不断地累积。
SELECT T1.日期, T1.型号, T1.时间, T1.宝贝标题, T1.店铺, T1.总销量, T1.型号id, T1.一口价, T1.销售价, T2.总销量,(T1.总销量-T2.总销量)/(T1.日期+T1.时间-T2.日期-T2.时间) AS 日销量, T1.总销量-T2.总销量AS 日销量累积, T1.重点关注, T1.类目代码, T1.销售价*日销量 AS 销售金额
FROM (SELECT A.日期, A.型号, A.时间, A.宝贝标题, A.店铺, A.总销量, A.型号id, A.一口价, A.销售价, A.重点关注, A.类目代码, count(*) AS 序列 FROM 合并查询0117 AS A, 合并查询0117 AS B WHERE A.型号id=B.型号id AND A.日期>=B.日期 GROUP BY A.日期, A.型号, A.时间, A.宝贝标题, A.店铺, A.总销量, A.型号id, A.一口价, A.销售价, A.重点关注, A.类目代码) AS T1
LEFT JOIN
(SELECT A.日期, A.型号, A.时间, A.宝贝标题, A.店铺, A.总销量, A.型号id, A.一口价, A.销售价, A.重点关注, A.类目代码, count(*) AS 序列 FROM 合并查询0117 AS A, 合并查询0117 AS B WHERE A.型号id=B.型号id AND A.日期>=B.日期 GROUP BY A.日期, A.型号, A.时间, A.宝贝标题, A.店铺, A.总销量, A.型号id, A.一口价, A.销售价, A.重点关注, A.类目代码) AS T2
ON (T1.型号id=T2.型号id) AND (T1.序列=T2.序列+1)
WHERE (T1.总销量-T2.总销量)/(T1.日期+T1.时间-T2.日期-T2.时间)>1
ORDER BY T1.日期; |