我的SQL查询如下: 我在该查询中使用内连接... 我想将其修改为子查询
select distinct Auditdata.ID,
ns.ProviderMaster_ID as CDRComment
from Auditdata AuditData
inner join AuditMaster am
on am.ID = AuditData.AuditMaster_ID
inner join HomeCircleMaster hcm
on hcm.Ori_CircleMaster_ID = am.CircleMaster_ID and hcm.Ori_ServiceTypeMaster_ID = 1 and hcm.Dest_ServiceTypeMaster_ID = 1 inner join AuditTaggingMaster atm
on atm.AuditMaster_ID = am.ID
inner join NoSeriesMaster ns on
( ns.CircleMaster_ID = am.CircleMaster_ID or ns.CircleMaster_ID = hcm.Dest_CircleMaster_ID) and ns.ProviderMaster_ID <> am.ProviderMaster_ID and ns.ServiceTypeMaster_ID = 1
inner join ProviderMaster_CallTypeMaster pm_ctm
on pm_ctm.ProviderMaster_ID = am.ProviderMaster_ID and pm_ctm.CallTypeMaster_ID = 101 and pm_ctm.CallTypeTagValue =AuditData.CallTypeTag INNER JOIN NoSeriesMaster_Prefix PD ON AuditData.CallTo like PD.PrefixNo + '%' AND AuditData.calltolen = PD.PrefixLen + PD.AfterPrefixLen AND PD.PrefixNo + ns.NoSeries = LEFT(AuditData.CallTo, NoSeriesLen + PD.PrefixLen) where AuditData.TATCallType is null and AuditData.AuditMaster_ID = 74 AND PD.PrefixType = 'SMS'
请帮帮我
感谢名单
答案 0 :(得分:3)
我会尝试发布美化的查询。否则很难提供帮助。试着解释你还想做什么。有6个内连接。你想改变哪一个? 无论如何。您的问题似乎与This one非常相似。请不要两次发布问题。
除此之外,您似乎正在尝试优化此查询。你为什么不问谁让它更快?在我看来,使用subquerys会让事情变得更糟。 如果您需要帮助优化,我们需要更多信息,如表结构,索引,行数等...
select distinct Auditdata.ID,
ns.ProviderMaster_ID as CDRComment
from Auditdata AuditData
inner join AuditMaster am on am.ID = AuditData.AuditMaster_ID
inner join HomeCircleMaster hcm on hcm.Ori_CircleMaster_ID = am.CircleMaster_ID
and hcm.Ori_ServiceTypeMaster_ID = 1
and hcm.Dest_ServiceTypeMaster_ID = 1
inner join AuditTaggingMaster atm on atm.AuditMaster_ID = am.ID
inner join NoSeriesMaster ns on ( ns.CircleMaster_ID = am.CircleMaster_ID
or ns.CircleMaster_ID = hcm.Dest_CircleMaster_ID)
and ns.ProviderMaster_ID <> am.ProviderMaster_ID
and ns.ServiceTypeMaster_ID = 1
inner join ProviderMaster_CallTypeMaster pm_ctm on pm_ctm.ProviderMaster_ID = am.ProviderMaster_ID
and pm_ctm.CallTypeMaster_ID = 101
and pm_ctm.CallTypeTagValue =AuditData.CallTypeTag
INNER JOIN NoSeriesMaster_Prefix PD ON AuditData.CallTo like PD.PrefixNo + '%'
AND AuditData.calltolen = PD.PrefixLen + PD.AfterPrefixLen
AND PD.PrefixNo + ns.NoSeries = LEFT(AuditData.CallTo, NoSeriesLen + PD.PrefixLen)
where AuditData.TATCallType is null
and AuditData.AuditMaster_ID = 74
AND PD.PrefixType = 'SMS