2 yarhsely yarhsely 于 2013.10.08 10:21 提问

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))

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

1个回答

en_joker
en_joker   2017.11.16 17:22

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!