日期:2014-05-18 浏览次数:20578 次
SELECT * from ( SELECT ROW_NUMBER() over(order by AuthorizedCode Desc) as rowId,MedicineId,NameCN,AuthorizedCode from T_Medicine WHERE AuthorizedCode IN ( SELECT AuthorizedCode FROM( SELECT AuthorizedCode,NameCN FROM dbo.Medicine WHERE AuthorizedCode!='' GROUP BY AuthorizedCode,NameCN ) tmp GROUP BY AuthorizedCode HAVING COUNT(*) > 1)) as t
SELECT ROW_NUMBER() over(order by AuthorizedCode Desc) as rowId,MedicineId,NameCN,AuthorizedCode from T_Medicine WHERE rowId between 20000 and 20020
SELECT * from ( SELECT ROW_NUMBER() over(order by AuthorizedCode Desc) as rowId,MedicineId,NameCN,AuthorizedCode from T_Medicine WHERE AuthorizedCode IN ( SELECT AuthorizedCode,NameCN FROM dbo.Medicine WHERE AuthorizedCode!='' GROUP BY AuthorizedCode,NameCN having count(AuthorizedCode)>1 ) ) as t
------解决方案--------------------
选中语句按下ctrl+L查看再条语句的执行计划,比较一下就会有所发现的
------解决方案--------------------
把
ELECT AuthorizedCode FROM(
SELECT AuthorizedCode,NameCN FROM dbo.Medicine WHERE AuthorizedCode!='' GROUP BY AuthorizedCode,NameCN
) tmp GROUP BY AuthorizedCode HAVING COUNT(*) > 1))
这一段放入到一个临时表中
最后主表和临时表做个连接。
分步来搞
------解决方案--------------------
表 'T_Medicine'。扫描计数 208920,逻辑读取 1998404 次,物理读取 0 次,预读 12 次,lob 逻辑读取 0 次,lob 物理读取 0 次,lob 预读 0 次。