select nianyue,count(*) as 连续月数
from table 
where 数量=0
group by nianyue having count(*)>6

解决方案 »

  1.   

    select yuef,count(*) as 6
    from jf_jifbzdl
    where chaojygdl = 0
    group by yuef having count(*) > 6我用的是sybase数据库,执行时说第一行语法错误
      

  2.   

    select distinct [id] from Utable as T
    where exists
    (select [id] from Utable where [id]=T.[id] and nianyue<=T.nianyue and count(*)>=6)
      

  3.   

    select distinct [id] from Utable as T
    where exists
    (select [id] from Utable where [id]=T.[id] and shuliang=0 and  nianyue<=T.nianyue-5 and count(*)>=6)