select DISTINCT subscriber_data.*
from subscriber_data, entities
where entities.id in
(
2,3,4,5,6,7,8,9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25,
26,27,28,29,30,31,32,33,34,35,36,37,38,39,1
)
and Lower( subscriber_data.status) in ( 'active','expired')
and (subscriber_data.entity_uid = entities.channel_uid
and subscriber_data.channel_id = entities.channel_id)
and Lower( subscriber_data.status) in ( 'active','expired')
order by subscriber_data.land_size desc LIMIT 0,10
答案 0 :(得分:0)
首先,在没有distinct
的情况下重写查询并修复您的数据,以便status
具有统一的大小写:
select sd.*
from subscriber_data sd
where exists (select 1
from entities e
where e.id in (2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,
26,27,28,29,30,31,32,33,34,35,36,37,38,39,1
) and
sd.entity_uid = e.channel_uid and
sd.channel_id = e.channel_id
) and
sd.status in ( 'active', 'expired')
order by sd.land_size desc
LIMIT 0, 10;
然后添加以下索引:subscriber_data(status, land_size, entity_uid, channel_id)
和entities(channel_uid, channel_id, id)
。