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
  • 相关阅读:
    02 序列模型问题
    02 序列模型问题
    04 电路交换
    31 路由算法.md
    NumPy入门教程
    有穷自动机
    上下文无关语法
    基本乐理
    正则表达式
    【OpenCV入门教程之七】 玩转OpenCV源代码:生成OpenCV工程解决方案与OpenCV源码编译(转)
  • 原文地址:https://www.cnblogs.com/zxxbk/p/6531157.html
Copyright © 2011-2022 走看看