Maison > Article > développement back-end > 帮忙看看,怎么简化这条mysql语句,并且优化查询效率~~~~~
有三张表:管理员表,部门表,和管理员对部门的打分表,如下:
select '' as type, `class`.`name` as cname, `score`.`cid`, `score`.`uid`, `user`.`name` as uname, `score`from `score`right join `class` on `score`.`cid` = `class`.`cid`left join `user` on `score`.`uid` = `user`.`uid`union all( select '汇总', `c`.`cname`, `c`.`cid`, `c`.`uid`, count(`cid`) as uname, sum(`score`) as score from ( select '' as type, `class`.`name` as cname, `score`.`cid`, `score`.`uid`, `user`.`name` as uname, `score` from `score` right join `class` on `score`.`cid` = `class`.`cid` left join `user` on `score`.`uid` = `user`.`uid` ) c group by `cname`)order by `cname` asc, `type` asc;
可以用一句简单的sql + 一段php程序进行实现吗
desc sql
对关键字段,加上索引看看
desc sql
对关键字段,加上索引看看 能具体点么?