MySQL学习_计算用户支付方式占比_20161104
Posted Mr_Cxy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL学习_计算用户支付方式占比_20161104相关的知识,希望对你有一定的参考价值。
计算用户支付方式占比
SELECT b.*#根据城市ID 年月排序 FROM ( SELECT a.* FROM ( #纵向合并 SELECT b1.ID,a1.城市,a1.收款方式,DATE_FORMAT(a1.确认时间,"%Y%m") AS 年月,SUM(a1.金额) AS 收款方式金额 FROM `a029_collectionment` AS a1 LEFT JOIN `a000_city` AS b1 ON a1.城市=b1.城市 WHERE a1.确认时间>"2016-01-01" AND a1.确认时间<CURRENT_DATE AND a1.收款方式="现金" GROUP BY a1.城市,DATE_FORMAT(a1.确认时间,"%Y%m") ) AS a UNION ALL ( SELECT d1.ID,c1.城市,c1.收款方式,DATE_FORMAT(c1.支付时间,"%Y%m") AS 年月,SUM(c1.金额) AS 收款方式金额 FROM `a031_order_paypal` AS c1 LEFT JOIN `a000_city` AS d1 ON d1.城市=c1.城市 WHERE c1.支付时间>"2016-01-01" AND c1.支付时间<CURRENT_DATE GROUP BY c1.城市,c1.收款方式,DATE_FORMAT(c1.支付时间,"%Y%m") ) ) AS b ORDER BY b.ID,b.年月
以上是关于MySQL学习_计算用户支付方式占比_20161104的主要内容,如果未能解决你的问题,请参考以下文章