mysql 查询子表,并求和,join改为子查询

日期:2019-02-14 浏览:543次

mysql 查询子表,并求和使用join,在EXPLAIN优化,发现性能很差,现改为子查询,代码为

运行结果

mysql查询语句:

SELECT `r`.`id`,`r`.`group`,`r`.`desc`,`r`.`time`,`r`.`status`,`r`.`short_url`,(SELECT count(distinct i.id) FROM `table_i` `i` WHERE `i`.`group_id` = r.id) as img_count,(SELECT sum(i.exec_sum) FROM `table_i` `i` WHERE `i`.`group_id` = r.id) as img_sum FROM `table_r` `r` WHERE `r`.`appid` = 34 ORDER BY r.id DESC LIMIT 0,10;

1 评论

发表评论