日期:2014-05-17 浏览次数:20467 次
update clku set cl_num2 = (select sum(clchu_num) where clchu_date between getdate() and dateadd(mm,9,getdate()) group by cl_class) from clku, clchu where clku.cl_class = clchu.cl_class
------解决方案--------------------
你的最近9个月是从现在开始往前数的9个月吗? 你首先获得9个月前的日期:
//9月前的日期
string startDate=DateTime.Now.AddMonths(-9).ToString() ;
//现在日期
string endDate=DateTime.Now.ToString() ;
update clku set cl_num2
= (select sum(clchu_num)/9 where clchu_date between startDate and endDate)
from clku, clchu where clku.cl_class = clchu.cl_class