询问一个SQL查询语句的问题,mysql的,来看看吧!
我的SQL语句如下 日中三个表数据量分别为 1700 13000 34 这样查询要40秒才会出来结果(我远程连的服务器MYSQL)。 我表示压力很大。请大神给予指示,
SQL code
SELECT COUNT(adverId) visit, adverId, statId developersName, productsName FROM tb_statistic_adver_visit v, (SELECT chid, uid, cpid FROM tb_statistic_stat) s, (SELECT developersName, productsName, developersId,id FROM tb_developers_service WHERE 1=1 GROUP BY developersId ) d WHERE 1=1 AND s.uid=v.statId AND s.cpid=d.developersId GROUP BY adverId
欢迎大家阅读《询问一个SQL查询语句的有关问题,MYSQL的,来看看吧》,跪求各位点评,by 搞代码
------解决方案--------------------
贴出explain..执行计划
------解决方案--------------------
这样嵌套的sql 我表示压力更大
------解决方案--------------------
要达到什么目的
贴建表及插入记录的SQL,及要求结果出来看看
------解决方案--------------------
贴出你的
show index from tb_statistic_adver_visit;
show index from tb_statistic_stat;
show index from tb_developers_service;
------解决方案--------------------
SQL code
show create table tb_statistic_adver_visit; show create table tb_statistic_stat; show create table tb_developers_service;
------解决方案--------------------SQL code
create index idx_v_statId on tb_statistic_adver_visit(statId); create index idx_s_cpid on tb_statistic_stat(cpid); create index idx_d_developersId on tb_developers_service(developersId);
------解决方案--------------------
SELECT
COUNT(adverId) visit,
adverId,
statId
developersName,
productsName
FROM
tb_statistic_adver_visit v,
tb_statistic_stat s
(SELECT
developersName,
productsName,
developersId,id
FROM
tb_developers_service
WHERE
1=1
GROUP BY
developersId ) d
WHERE
1=1
AND s.uid=v.statId
AND s.cpid=d.developersId
GROUP BY
adverId
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~