SELECT *
FROM price_t
WHERE country = 'US'
AND price_type = 'SalesPrice'
AND del_dtime IS NULL
AND item_no IN
(SELECT item_no
FROM price_t a
WHERE country = 'US'
AND del_dtime IS NULL
AND EXISTS
(SELECT *
FROM price_t
WHERE country = a.country
AND price_type = a.price_type
AND currency_code = a.currency_code
AND item_no = a.item_no
AND ( from_dtime BETWEEN a.from_dtime AND a.to_dtime
OR to_dtime BETWEEN a.from_dtime AND a.to_dtime
OR (from_dtime > a.from_dtime
AND a.to_dtime IS NULL)
OR (from_dtime < a.from_dtime
AND to_dtime IS NULL) )
AND del_dtime IS NULL
AND NOT ( a.rowid = rowid )
)
)
ORDER BY item_no, from_dtime;
Приведенный выше запрос занимает 12 se c, чтобы дать ответ. Без заказа на 9 се c резонанс. Как его оптимизировать, чтобы дать ответ в 2se c.