mysql查询优化问题

select * from (select * from status where 1=1 ".$sch_q." order by stime desc ) as tmp where 1=1 ".$sch_s." group by name

'select * from (select * from (select * from status where 1=1 '.$sch_q.' order by stime desc ) as tmp group by name) as tmpp where status in (0,1,2,3)'.$sch_s

像这种select子查询该怎么优化 有谁可以帮帮忙吗? 万分感谢!!!

注:

$sch_q = ' ';
$sch_s = ' ';
阅读 2.5k
3 个回答

你的这个sql真的能运行么? 第一层子查询里 group by name ,那么查询字段也只能是name或者聚合字段,select * 应该会报错的。

打开mysql query_cache

如果需要优化查询语句,最好先用explain 测试一下,然后看相关的参数进行优化。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题