zoukankan      html  css  js  c++  java
  • mysql_db_sql_Sum集合中两个表不能内连接,提高查询效率

    需要根据时间进行查询这段时间洗了多少次车
    SELECT wx.UserName AS '用户名称', wx.Telephone AS '手机号', IFNULL(TotalCarCount,0) AS '共洗车次数', IFNULL(BigCarCount,0) AS '大车洗车次数', IFNULL(SmallCarCount,0) AS '小车洗车次数', IFNULL(count(WashOrderID),0) AS '充值总次数', IFNULL(SUM(case cd.CardType when 13 then 1 else 0 end),0) AS '充值次数', IFNULL(SUM(case cd.CardType when 12 then 1 else 0 end),0) AS '购卡次数', IFNULL(FORMAT(SUM(cd.WashOrderActualMoney),2),0) AS '实际消费金额', IFNULL(SUM(WashOrderIntegral*sc.ConfigValue),0) AS '积分使用量', IFNULL(FORMAT(SUM(cd.WashOrderDeductible),2),0) AS '优惠券使用金额' FROM t_wxuserinfos AS wx LEFT JOIN (SELECT * FROM t_cardrechargedetails WHERE WashOrderSign = 'e252a4a9-536a-4eb3-ae40-a7b9df95176b') cd ON wx.UserID=cd.UserID LEFT JOIN t_carwashinformation ci ON wx.UserID=ci.UserID
    LEFT JOIN (SELECT ConfigValue FROM t_sysconfig WHERE ConfigName='integralMoneyRatio') AS sc ON 1=1 LEFT JOIN (SELECT UserID,COUNT(oc.OrderID) AS TotalCarCount,SUM(case oc.CarTypeID when 1 then 1 else 0 end) AS BigCarCount, SUM(case oc.CarTypeID when 2 then 1 else 0 end) AS SmallCarCount FROM t_orderconsumption AS oc GROUP BY UserID) AS b ON wx.UserID = b.UserID GROUP BY wx.UserID 加粗为关键的 SELECT cd.WashOrderTime FROM t_cardrechargedetails cd
  • 相关阅读:
    Spring-Cloud之Feign
    Spring-Cloud之Ribbon原理剖析
    Spring-Cloud之Ribbon
    Spring-Cloud之Eureka
    显示列表
    顶点缓存对象(VBO)
    OpenGL观察轴
    OpenGL顶点数组
    OpenGL投影矩阵
    OpenGL变换
  • 原文地址:https://www.cnblogs.com/zxxbk/p/6531157.html
Copyright © 2011-2022 走看看