高手帮优化下如何改成 join 格式

elite2018 2019-01-20 11:18:46
select count(id) ,IFNULL(sum(s_num),0) ,IFNULL(sum(p),0),
(select count(id) from es where `status` in(2,3) and t_id in(1,2,3)) as a,
(select count(id) from r where r.stat=0 and c_id in(
select id from c where stat >0 and t_id in(1,2,3))) as b,
(select count(id) from c where c.stat >0 and t_id in(1,2,3) and c.p > (
select count(user_id) from s where c.id = s.c_id)) as cc,
(select count(user_id) from s where c_id in(
select id from c where stat >0 and t_id in(1,2,3))) dd
from c where `stat`!=0 and t_id in(1,2,3);
其中s表超级大,百万行,其他表几万行,如何改成 join 格式,并减少c,s表的调用次数
...全文
212 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
吉普赛的歌 2019-01-23
  • 打赏
  • 举报
回复
所谓优化, 如果不考虑升级硬件,95%的情况下是百里挑一, 万里挑一。 至于改下写法就能优化的, 只能占5% , 而且也没办法处理全表扫描。 这么多表聚合, 基本上相当于全表扫描了, 除非 in (1,2,3)这几个值属于唯一性高的情况。 如果不是, 基本上没太多可以优化的了。
AHUA1001 2019-01-23
  • 打赏
  • 举报
回复
没有数据,看着真的有难度,其实你只要看懂了join的用法,就可以自己改了。join其实也不难。
  • 打赏
  • 举报
回复
写得好乱啊。。。
落地的果实 2019-01-22
  • 打赏
  • 举报
回复
第二行是from s吗? 不是es吧
elite2018 2019-01-21
  • 打赏
  • 举报
回复
顶顶顶顶顶顶

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧