zoukankan      html  css  js  c++  java
  • 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.年月
  • 相关阅读:
    java 字符串截取
    字符编码Unicode-正则表达式验证
    APP数据加密解密
    ThreadLocal线程局部变量
    用Eclipse进行远程Debug代码
    JPA对应关系
    JPA名称规则
    dubbo环境搭建
    历史表更新数据
    api加密算法
  • 原文地址:https://www.cnblogs.com/Mr-Cxy/p/6031841.html
Copyright © 2011-2022 走看看