查询根据机器号 分组查出上个月跟上上个月的总交易额度,并计算流失率
SELECT
yonghuming,tongjiriqi,
sn,
SUM( jine ) AS total_jine
FROM
h_erp_transaction_data
WHERE
(`pinpai` = '立刷' and `tongjiriqi` BETWEEN '2024-04-01' AND '2024-04-30' ) or (`pinpai` = '立刷' and `tongjiriqi` BETWEEN '2024-03-01' AND '2024-03-30' )
GROUP BY sn ORDER BY yonghuming desc
SELECT
yonghuming,tongjiriqi,
sn,
SUM(
CASE
WHEN MONTH(tongjiriqi) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH) THEN jine
ELSE 0
END
) AS '上月总金额',
SUM(
CASE
WHEN MONTH(tongjiriqi) = MONTH(CURRENT_DATE - INTERVAL 2 MONTH) THEN jine
ELSE 0
END
) AS '两个月前总金额'
FROM
h_erp_transaction_data
WHERE
(`pinpai` = '立刷' and `tongjiriqi` BETWEEN '2024-04-01' AND '2024-04-30' ) or (`pinpai` = '立刷' and `tongjiriqi` BETWEEN '2024-03-01' AND '2024-03-30' )
GROUP BY sn ORDER BY yonghuming desc
SELECT CURDATE(),CURRENT_DATE(),CURRENT_DATE,CURRENT_DATE - INTERVAL 1 MONTH, MONTH(CURRENT_DATE - INTERVAL 2 MONTH);
SELECT
yonghuming,tongjiriqi,
sn,
SUM(
CASE
WHEN MONTH(tongjiriqi) = 4 THEN jine
ELSE 0
END
) AS '上月总金额',
SUM(
CASE
WHEN MONTH(tongjiriqi) = 3 THEN jine
ELSE 0
END
) AS '两个月前总金额'
FROM
h_erp_transaction_data
WHERE
(`pinpai` = '立刷' and `tongjiriqi` BETWEEN '2024-04-01' AND '2024-04-30' ) or (`pinpai` = '立刷' and `tongjiriqi` BETWEEN '2024-03-01' AND '2024-03-30' )
GROUP BY sn ORDER BY yonghuming desc
查询根据机器号 分组查出上个月跟上上个月的总交易额度,并计算流失率
原创
©著作权归作者所有:来自51CTO博客作者小楚留香的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
我干了两个月的大项目,开源了!
我肝了 2 个多月的大项目《智能协同云图库》,终于完结了!
服务器 程序员 编程 开源 项目学习 -
pytorch搭建CNN进行房价预测
文章目录1. Kaggle比赛2. 获取和读取数据集3. 预处理数据4. 训练模型5. K K K折交叉验证6. 模
pytorch搭建CNN进行房价预测 深度学习 人工智能 机器学习 pytorch