sql 查询优化问题
我用sql做了服务器外链,外链服务器的数据库存是oracle,我在sql上写了分页查询:
SELECT top 10 * FROM OPENQUERY(LINK,'select * From cmn.qx')
where id not in (select top 20 id from OPENQUERY(LINK,'select * From cmn.qx')) order by id"
这是SQL语句,中间可能还会有一些条件
请大神说下优化方案
[解决办法]
都是从LINK取数据,2个OPENQUERY()应可合并为1个OPENQUERY().
[解决办法]
--仅供参考
--查询10-20之间的号码
SELECT * FROM OPENQUERY
(
LINK,
'
SELECT TOP 20 *
FROM cmn.qx
WHERE ID NOT IN
(
SELECT TOP 10 ID
FROM cmn.qz
ORDER BY id
)
ORDER BY id
'
)
select top 30 *
into #tb
from OPENQUERY(LINK,'select * From cmn.qx'))
order by id
select top 10 *
from #tb
order by id desc