SELECT value
FROM test t
WHERE EXISTS(
SELECT 1
FROM test t1
WHERE t.value=t1.value
AND t.date<>t1.DATE)

解决方案 »

  1.   

    查重复:
    select value from test group by value having count(*)>1
      

  2.   

    也想知道在什么地方写日期的限制,比如 date>2006-1-1 and date<2006-1-4 ?
      

  3.   

    declare @t table(VALUE char(3),[Date] datetime)
    insert @t 
    select '123','2006-1-1' union all
    select '333','2006-1-1' union all
    select '555','2006-1-1' union all
    select '777','2006-1-1' union all
    select '666','2006-1-1' union all
    select '123','2006-1-2' union all
    select '125','2006-1-2' union all
    select '333','2006-1-2' union all
    select '888','2006-1-2' union all
    select '123','2006-1-3' union all
    select '126','2006-1-3' union all
    select '333','2006-1-3' union all
    select '888','2006-1-3'select distinct A.VALUE from @T A,@T B,
    (select 1 as N
    union all select 2
    union all select 0
    ) C
    where A.VALUE=B.VALUE 
    and B.[date]=dateadd(d,N,A.[date])
    group by A.VALUE
    having(count(*)>3)/*VALUE 
    ----- 
    123
    333*/
      

  4.   

    我上面的语句是连续三天内出现的value
      

  5.   

    select value from 表 where date between '2006-1-1' and '2006-1-3' group by value having count(*)>1 
      

  6.   

    select value 
    from test
    where date>'2006-01-01' and date <'2006-01-04'
    group by value 
    having count(*)>1
      

  7.   

    SELECT value
    FROM test t
    WHERE EXISTS(
    SELECT 1
    FROM 
    (select value,date from test
    WHERE value=t.value
    AND date=t.date
    union all
    select value,date from test
    WHERE value=t.value
    AND date=dateadd(dd,1,t.date)
    union all
    select value,date from test
    WHERE value=t.value
    AND date=dateadd(dd,2,t.date)
    )
      

  8.   

    select value from temp2
    where date>=dateadd(day,-1,getdate())
    and date<=dateadd(day,3,getdate())
    group by value
    having count(value)>1
      

  9.   

    不好意思再改下,--三天中都有重复的,
    SELECT value
    FROM test t
    WHERE EXISTS(
    SELECT 1
    FROM 
    (select ditinct value from test
    WHERE value=t.value
    AND date=t.date
    union all
    select distinct value from test
    WHERE value=t.value
    AND date=dateadd(dd,1,t.date)
    union all
    select distinct value from test
    WHERE value=t.value
    AND date=dateadd(dd,2,t.date)
    ) a group by a.value having count(*)=3)
      

  10.   

    declare @test table
    (VALUE varchar(10),Date datetime)
    insert @test
    select '123','2006-1-1' union all
    select '333','2006-1-1' union all
    select '555','2006-1-1' union all
    select '777','2006-1-1' union all
    select '666','2006-1-1' union all
    select '123','2006-1-2' union all
    select '123','2006-1-2' union all
    select '333','2006-1-2' union all 
    select '888','2006-1-2' union all
    select '333','2006-1-3' union all 
    select '888','2006-1-3' union all
    select '123','2006-1-4' union all
    select '888','2006-1-4' union all
    select '888','2006-1-4'select distinct a.value from @test a
    inner join @test b on a.value=b.value and datediff(d,a.date,b.date)=1
    inner join @test c on a.value=c.value and datediff(d,a.date,c.date)=2 and datediff(d,b.date,c.date)=1
    value      
    ---------- 
    333
    888(所影响的行数为 2 行)