求大神优化千万级库的语句set statistics time ondeclare@userid int 4declare @count int set @count
求大神优化千万级库的语句
set statistics time on
declare @userid int =4
declare @count int set @count = (select COUNT(*) from UT_PROGRAM where UserID=@userid and TYPE<>0); select userid, (select sum(2 - abs(u1.type-u2.type)) from UT_PROGRAM u1 join UT_PROGRAM u2 on u1.ProgramID=u2.ProgramID where u1.UserID=@userid and u1.TYPE<>0 and u2.UserID=u.userid and u2.TYPE<>0)*1.0/((select COUNT(*)+ @count from UT_PROGRAM where UserID=u.UserID and TYPE<>0) ) as s from dbo.UT_USER u where u.UserID<>@userid order by UserID