请问一下,这条SQL 能优化吗?

Www_XSimon_cN 2016-01-07 09:15:58

set @x_sum_zs=(SELECT id from __TABLE__ order by rq desc limit 1)+1;
set @x_sum_px=@x_sum_zs;

select *,@x_sum_px:=(@x_sum_px-1) as sum_px,
(SELECT SUM(hsl) from __TABLE__ where id between @x_sum_px and @x_sum_zs ) as hsl_sum ,
(SELECT SUM(cjl) from __TABLE__ where id between @x_sum_px and @x_sum_zs ) as cjl_sum ,
(SELECT SUM(zdf) from __TABLE__ where id between @x_sum_px and @x_sum_zs ) as zdf_sum ,
(SELECT SUM(cjje) from __TABLE__ where id between @x_sum_px and @x_sum_zs ) as cjje_sum
from __TABLE__ order by id desc limit 370
...全文
187 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
LongRui888 2016-01-12
  • 打赏
  • 举报
回复
你这个 (SELECT SUM(hsl) from __TABLE__ where id between @x_sum_px and @x_sum_zs ) as hsl_sum 是什么意思,而你后面又是 limit 370 你是不想让 limit 370 影响到 上面求sum,才这么写的吗?
文修 2016-01-08
  • 打赏
  • 举报
回复
楼主你好 确实不能优化,如果执行时间不是很长的话,可以不用优化
Www_XSimon_cN 2016-01-07
  • 打赏
  • 举报
回复
晕,,,看来真的不能优化了~

56,679

社区成员

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

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