MySQL 查询优化问题 [ 2.0 版本 ]
SELECT sum(gross_margin) AS `gross_sum` FROM `yn_goods_analyze_shop_by_day` WHERE (`create_date` BETWEEN '2019-05-13' AND '2019-05-19') AND (spid in (SELECT `spid` FROM `yn_goods_analyze_shop_by_day` WHERE `create_date` BETWEEN '2019-05-13' AND '2019-05-19' GROUP BY `spid` HAVING round(sum(saleroom)*0.88-sum(goods_cost)-6,1) < 0))
表头统计的合计 执行时间太长 搜索总是超时,希望大神指点一下,这个 SQL 语句该怎么优化
EizoPeter 补充于 2019-05-21 10:36
最后解决的方案
最佳答案
-
in 改为join模式
共 2 条回复SELECT sum(gross_margin) AS
gross_sum
FROMyn_goods_analyze_shop_by_day
WHERE (create_date
BETWEEN '2019-05-13' AND '2019-05-19') AND (spid join (SELECTspid
FROMyn_goods_analyze_shop_by_day
WHEREcreate_date
BETWEEN '2019-05-13' AND '2019-05-19' GROUP BYspid
HAVING round(sum(saleroom)*0.88-sum(goods_cost)-6,1) < 0))
改成这样吗 ? 这样会报语法错误@花椒
SELECT sum(gross_margin) ASgross_sum
FROMyn_goods_analyze_shop_by_day
join (SELECTspid
FROMyn_goods_analyze_shop_by_day
WHEREcreate_date
BETWEEN '2019-05-13' AND '2019-05-19' GROUP BYspid
HAVING round(sum(saleroom)*0.88-sum(goods_cost)-6,1) < 0) AS u WHERE (create_date
BETWEEN '2019-05-13' AND '2019-05-19')
这样写得到的结果不对 应该怎么写大佬 求指导 QAQ
其他 0 个回答
没有找到数据。
EizoPeter
注册时间:2018-08-30
最后登录:2020-06-18
在线时长:34小时12分
最后登录:2020-06-18
在线时长:34小时12分
- 粉丝6
- 金钱2775
- 威望0
- 积分3115