0

我有一个应用程序,可以在其中选择很多选项,其中有四个表,每个过滤器可能有 4 个不同的术语,如果我们进行值计数,并且我不擅长查询,只知道如何获得所需的结果。所以查询可以是:

select distinct(maindbgroupid) from ((SELECT mainDBGroupID from 
groupstatisticsdata.seniority where ( `name` = 'Senior' )AND maindbgroupid in (SELECT 
mainDBGroupID from groupstatisticsdata.Function where ( `name` = 'Information Technology' 
)AND (`Value` >1000) AND maindbgroupid in (SELECT mainDBGroupID from 
groupstatisticsdata.Industry where ( `name` = 'Information Technology and Services' )AND 
(`Value` >1000))))) t join maingroupdb.campaigns on campaigns.groupid=t.maindbgroupid 
where campaigns.campaignName='Campaign1101'

这是一个例子,请如何改进它,因为当我使用多个过滤器时总是会超时。

我在查询中所做的是表之间的相交。

4

1 回答 1

0

试试这个 ::

select distinct(mainDBGroupID)
 from 
 groupstatisticsdata.seniority
 inner join groupstatisticsdata.Function on (groupstatisticsdata.seniority.maindbgroupid=groupstatisticsdata.Function.mainDBGroupID)
inner join  groupstatisticsdata.Industry on (groupstatisticsdata.Industry.mainDBGroupID=groupstatisticsdata.seniority.maindbgroupid)
inner join maingroupdb.campaigns on campaigns.groupid=t.maindbgroupid 
where groupstatisticsdata.seniority.`name` = 'Senior'  AND 
 groupstatisticsdata.Function.`name` = 'Information Technology' 
 AND `Value` >1000 
 AND maindbgroupid 
AND groupstatisticsdata.Industry.`name` = 'Information Technology and Services' )
AND 
groupstatisticsdata.Industry.`Value` >1000 
AND campaigns.campaignName='Campaign1101'
于 2012-07-09T05:11:27.317 回答