SQL code:
declare @begin datetime --¿ªÊ¼Ê±¼ä
declare @end datetime --½áÊøʱ¼ä
declare @startIndex int --ÆðʼֵĬÈÏΪ8
declare @interval int --ʱ¶Î³¤
select @startIndex=8
select @interval=12
if @interval=6
begin
select stcd,convert(varchar(10),TM,20)'ÈÕÆÚ',sum(dyp)'ÈÕÓêÁ¿',
sum(case when @startIndex+@interval=14 then p8+p9+p10+p11+p12+p13 else 0 end) 'h14',
sum(case when @startIndex+@interval=20 then p14+p15+p16+p17+p18+p19 else 0 end) 'h20',
sum(case when @startIndex+@interval=26 then p20+p21+p22+p23+p0+p1 else 0 end) 'h02',
sum(case when @startIndex+@interval=32 then p2+p3+p4+p5+p6+p7 else 0 end) 'h08'
from st_rain_s where tm>'2009-3-01' and tm<'2010-4-2'
group by stcd,convert(varchar(10),TM,20)
end
else if @interval=8
begin
select stcd,convert(varchar(10),TM,20)'ÈÕÆÚ',sum(dyp)'ÈÕÓêÁ¿',
sum(case when @startIndex+@interval=16 then p8+p9+p10+p11+p12+p13+p14+p15 else 0 end) 'h16',
sum(case when @startIndex+@interval=20 then p16+p17+p18+p19+p20+p21+p22+p23 else 0 end) 'h24',
sum(case when @startIndex+@interval=26 then p0+p1+p2+p3+p4+p5+p6+p7 else 0 end) 'h08'
from st_rain_s where tm>'2009-3-01' and tm<'2010-4-2'
group by stcd,convert(varchar(10),TM,20)
end
else
begin
select stcd,convert(varchar(10),TM,20)'ÈÕÆÚ',sum(dyp)'ÈÕÓêÁ¿',
sum(case when @startIndex+@interval=16 then p8+p9+p10+p11+p12+p13+p14+p
ÎÒÓжà¸ö±íA B C ½á¹¹ÊÇÒ»ÑùµÄ£¬¶¼ÓÐ2¸ö×Ö¶ÎnameºÍcontent,ÎÒÒªËÑË÷ËùÒÔ±íËùÓÐ×Ö¶ÎÖаüº¬¡°Öйú¡±µÄÄÚÈÝ Õâ¸öSQLÓï¾äÔõôд
ÈçºÎ½«¶à¸ö±íµÄ²éѯ½á¹ûÁ¬³ÉÒ»¸ö±í Õâ¸öSQLÓï¾äÔõôд ±íµÄ½á¹¹ÊÇÒ»ÑùµÄ
ÀýÈç£ ......