求连续数据


(select * from @t c where not exists(select 1 from @t where 名称=c.名称 and 年份=c.年份 and 月份=c.月份-1)) a,
求最小值
(select * from @t d where not exists(select 1 from @t where 名称=d.名称 and 年份=d.年份 and 月份=d.月份+1)) b
求不连续数据的起始值


按照名称查出同一年中其中查出连续6个月有数据的名称。



select 名称,年份,cast(min(月份) as varchar(2))+'-'+cast(max(月份+5) as varchar(2)) 月份
from @t t
where (
      select count(distinct(a.月份))
        from @t a
       where a.年份=t.年份  and a.名称=t.名称 and a.月份 between t.月份 and t.月份+5
) >5
group by 名称,年份
order by 名称,年份 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值