我在mysql中运行此查询,即使等待几个小时也无法完成。
select *
from merged as rm
inner join client_Master as E on E.Code = rm.Code
inner join client_loan_details as d on (d.Loan_Account = rm.loanacno or rm.savingacno = d.SavingAccount) and d.id = E.id
group by rm.client_name;
由于表中的行(merged和client_loan_details)是1000万,因此需要时间。我已经检查过mysql正在使用正确的索引,这应该不是问题。但我想知道我的查询是否正确。 我用d连接表rm,表E是一个中间表。根据SQL标准查询是正确的还是我遗漏了什么?
答案 0 :(得分:1)
我在加入时OR
的表现也不好。尝试将其从连接中取出。没有任何聚合的GROUP BY
语句正在执行DISTINCT
,但只在一列上进行,而您只选择所有聚合。对我来说似乎毫无用处。
select *
from merged as rm
inner join client_Master as E on E.Code = rm.Code
inner join client_loan_details as d on d.id = E.id
WHERE (d.Loan_Account = rm.loanacno or rm.savingacno = d.SavingAccount)