我有一个应用程序,可以选择很多选项,其中有四个表和每个过滤器可能有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'
这是一个例子,如何改进它,因为当我使用多个过滤器时总是会超时。
我在查询中所做的是表之间的交叉。
答案 0 :(得分: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'