`
王非123
  • 浏览: 23955 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

sql server 一年内连续降雨几天及开始结束日期

    博客分类:
  • sql
 
阅读更多

 select
     min(tm) 'startday',
     max(tm) 'endday',
     count(1) 'lxday',
     SUM(avgz) avgz
 from
 (


  select a.tm,a.avgz,
   datepart(Y,a.tm)-
     (
       select count(1) from
      (
     select * from (
select datepart(mm,ts.TM) as mm,  datepart(dd,ts.TM) as dd,avg(ts.DRP) as avgz,ts.tm from ST_PPTN_DAY_R ts left join ST_STBPRP_B f on ts.STCD = f.stcd where ts.TM>='2016-01-01 00:00:00' and ts.TM<'2016-12-31 23:59:59'  group by datepart(mm,ts.TM) ,datepart(dd,ts.TM),ts.tm
) ag  where avgz >0

      ) b
     where  b.tm<=a.tm
        
   ) 'rn'
    from
    (
     select * from (
select datepart(mm,ts.TM) as mm,  datepart(dd,ts.TM) as dd,avg(ts.DRP) as avgz,ts.tm from ST_PPTN_DAY_R ts left join ST_STBPRP_B f on ts.STCD = f.stcd where ts.TM>='2016-01-01 00:00:00' and ts.TM<'2016-12-31 23:59:59'  group by datepart(mm,ts.TM) ,datepart(dd,ts.TM),ts.tm
) ag  where avgz >0

    )a
   
 
 ) t
 
 group by rn;

 

8个雨量站的平均降雨量

select datepart(mm,ts.TM) as mm,  datepart(dd,ts.TM) as dd,avg(ts.DRP) as avgz,ts.tm from ST_PPTN_DAY_R ts left join ST_STBPRP_B f on ts.STCD = f.stcd where ts.TM>='2016-01-01 00:00:00' and ts.TM<'2016-12-31 23:59:59' group by datepart(mm,ts.TM) ,datepart(dd,ts.TM),ts.tm

 


 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics