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
'
)
------解决方案--------------------1. Oracle木有"top 10.."喔.
2. not in (select...) -->此处的select不能有order by子句.
------解决方案--------------------select top 30 *
into #tb
from OPENQUERY(LINK,'select * From cmn.qx'))
order by id
select top 10 *
from #tb
order by id desc
------解决方案--------------------要注意不同数据库之间的语法差异