求一条SQL语句
如何把:
select top 12 * from WJ_EnterpriseSummary where Guid not in(select top 24 Guid from WJ_EnterpriseSummary where 1=1 order by companyGuid asc,sumYear desc,sumMonth desc) order by companyGuid asc,sumYear desc,sumMonth desc
not in 转换为not exists
------解决方案--------------------个人感觉:
Oracle中测试:
这种SQL不需要采用not exists,因为子查询只有24条记录。
而且SQL Server中也需要子查询:
select top 12 parent.* from WJ_EnterpriseSummary parent where
not exists
(select 1 from (select top 24 Guid from WJ_EnterpriseSummary order by companyGuid asc,sumYear desc,sumMonth desc) child where parent.Guid =child.Guid )
order by parent.companyGuid asc,parent.sumYear desc,parent.sumMonth desc
请测试两种方法的效果并回帖,谢谢!
------解决方案--------------------声称临时表不可取,如果多用户同时操作,相互覆盖怎么办?
————————————————————————————————
哈哈,原来是这样原因啊;楼主放心好了,不同用户访问,生成的临时表#是不同的!
带#号的临时表只对当前会话有效。