SQL语句效率太低,2万条数5分钟还没有查询出来...
这是昨天的问题:
但是速度太慢了...
select distinct a.[No], a.code, a.codename,a.nume,(case when a.nume = 0 then 0 when a.nume < b.nume then 0 else (a.nume - b.nume) * 1.0 / a.nume end) as 不良
from (select [No], code, codename , (isnull(Anumeric,0) + isnull(Bnumeric,0) + isnull(Cnumeric,0)) as nume from V_work) a
join (select [Lot No], code, codename, (isnull(Anumeric,0) + isnull(Bnumeric,0) + isnull(Cnumeric,0)) as nume from V_work) b
on b.code = (select min(code) from V_work where code > a.code)
where a.[No] in(select distinct [No] from v_work where stdate between '2006-04-01' and '2006-04-10')
order by a.[No], a.code
请各位大侠帮忙看看,谢谢!
那个V_work是个简单的视图,只是从一个表里取相应的字段而已,应该没什么问题...