sqlserver数据库怎样优化代码

select
c.participant_name,
c.login_id,
@year as y,
datepart(MONTH,receive_date) as m,
b.phase_name as lc,
m.manu_number as gh,
max(datediff(day, m.submit_date, a.submit_date)) as t
from manuflow a
left join review_phase b on a.phase_id=b.phase_id
left join participant c on a.submitter_id=c.participant_id,manuscript m
where
(@editor='' or c.participant_name=@editor)
and receive_date>=(@year+'-1-1') and receive_date<( cast(cast(@year as int)+1 as varchar(4))+'-1-1' )
and not c.login_id is null
and not c.participant_name is null
and a.submit_date >= (@year+'-1-1') and a.submit_date<( cast(cast(@year as int)+1 as varchar(4))+'-1-1' )
and m.submit_date >= (@year+'-1-1') and m.submit_date<( cast(cast(@year as int)+1 as varchar(4))+'-1-1' )
and m.submit_date <= a.submit_date
and b.phase_name = 'szs'
and m.manu_number in(select manu_number from #GH)
group by b.phase_name,m.manu_number,c.participant_name,c.login_id,datepart(MONTH,receive_date)
order by c.participant_name,c.login_id,datepart(MONTH,receive_date),b.phase_name,m.manu_number,max(datediff(day, m.submit_date, a.submit_date))

怎么能让它运行的更快一些

sql

1个回答

查询语句优化,万变不离其宗。
推荐你看看这篇博文。
http://blog.csdn.net/en_joker/article/details/78161898

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐