select cCusCode,CCusName,paytype,sum(iPrice) iPrice,dVeriDate
from rdrecords as rs
left join rdrecord as r on rs.rdfk = r.rdpk
where r.uid = '1' and rs.uid = '1' and r.cStatus = '1' and rs.rdsrowstatus='0' and r.cCusCode = '10014'
and (r.cVouchType ='xxck' or r.cVouchType ='xscj' or r.cVouchType ='fpck' or r.cVouchType ='fpckcj') and r.bRdFlag='1'
group by rs.paytype
------解决方案-------------------- explain select cCusCode,CCusName,paytype,sum(iPrice) iPrice,dVeriDate from rdrecords as rs left join rdrecord as r on rs.rdfk = r.rdpk where r.uid = '1' and rs.uid = '1' and r.cStatus = '1' and rs.rdsrowstatus='0' and r.cCusCode = '10014' and (r.cVouchType ='xxck' or r.cVouchType ='xscj' or r.cVouchType ='fpck' or r.cVouchType ='fpckcj') and r.bRdFlag='1' group by rs.paytype
show index from 连接表名 贴结果 在连接字段上建立索引没有
------解决方案-------------------- create index xx on rdrecords(paytype,uid,rdsrowstatus)
------解决方案-------------------- SQL语句不是标准的 select cCusCode,CCusName,paytype,sum(iPrice) iPrice,dVeriDate from rdrecords as rs left join rdrecord as r on rs.rdfk = r.rdpk where r.uid = '1' and rs.uid = '1' and r.cStatus = '1' and rs.rdsrowstatus='0' and r.cCusCode = '10014' and (r.cVouchType ='xxck' or r.cVouchType ='xscj' or r.cVouchType ='fpck' or r.cVouchType ='fpckcj') and r.bRdFlag='1' group by cCusCode,CCusName,paytype
将OR->UNION ALL
------解决方案-------------------- select cCusCode,CCusName,paytype,sum(iPrice) iPrice,dVeriDate from rdrecords as rs left join rdrecord as r on rs.rdfk = r.rdpk where r.uid = '1' and rs.uid = '1' and r.cStatus = '1' and rs.rdsrowstatus='0' and r.cCusCode = '10014' and r.cVouchType ='xxck'and r.bRdFlag='1' group by cCusCode,CCusName,paytype union all select cCusCode,CCusName,paytype,sum(iPrice) iPrice,dVeriDate from rdrecords as rs left join rdrecord as r on rs.rdfk = r.rdpk where r.uid = '1' and rs.uid = '1' and r.cStatus = '1' and rs.rdsrowstatus='0' and r.cCusCode = '10014' and r.cVouchType ='xscj'and r.bRdFlag='1' group by cCusCode,CCusName,paytype ....
------解决方案-------------------- 贴出你的show index from rdrecords; show index from rdrecord;
explain select cCusCode,CCusName,paytype,sum(iPrice) iPrice,dVeriDate from rdrecords as rs left join rdrecord as r on rs.rdfk = r.rdpk where r.uid = '1' and rs.uid = '1' and r.cStatus = '1' and rs.rdsrowstatus='0' and r.cCusCode = '10014' and (r.cVouchType ='xxck' or r.cVouchType ='xscj' or r.cVouchType ='fpck' or r.cVouchType ='fpckcj') and r.bRdFlag='1' group by rs.paytype
------解决方案--------------------
------解决方案-------------------- 1) #11楼 上的信息反应 根本没有创建需要的索引。rdrecord(uid,cCusCode,cStatus,bRdFlag) 2)MYSQL在第一次执行完一个SQL语句后,后进行缓存。这样第二次执行相同语句的时候,则可以直接从缓存中取数据。
------解决方案-------------------- 再贴一下你的 show index 和 explain
------解决方案--------------------