f1    f2   f3   f4
1     a1   b1   c1 
2     a1   b1   c1 
3     a1   b1   c1 4     a2   b2   c2 
5     a2   b2   c2 6……
---------------------------
说明:
1、F1为自动增长型字段
2、要求:
   如上,1~3中,f2的值都是a1,f4的值都是c1,这形成一个区间,
   4~5中,同理,也是一个区间   要求,f3的值在此区间内都要相同,如果有不同的,则通过一条
   SQL检测出来,比如f1    f2   f3   f4
1     a1   b1   c1 
2     a1   b3   c1 
3     a1   b1   c1 4     a2   b2   c2 
5     a2   b2   c2 另:只需要检测出有无异常即可,无需具体指定F3字段中的哪一个值,即IF EXISTS……即可
----------------------------------------------------------------谢谢

解决方案 »

  1.   

    drop table tb
    create table tb(f1 int identity ,f2 varchar(2) ,f3  varchar(2) ,f4 varchar(2) )
    insert tb
    select 'a1','b1','c1' union all
    select 'a1','b3','c1' union all
    select 'a1','b1','c1' union allselect 'a2','b2','c2' union all
    select 'a2', 'b2','c2' 
    select * from tb t
    where exists(select 1 from tb where f2=t.f2 and f4=t.f4 and f3<>t.f3)/*
    f1          f2   f3   f4   
    ----------- ---- ---- ---- 
    1           a1   b1   c1
    2           a1   b3   c1
    3           a1   b1   c1(所影响的行数为 3 行)*/
      

  2.   

    本帖最后由 roy_88 于 2010-06-18 17:44:50 编辑
      

  3.   

    create table tb(f1 int identity ,f2 varchar(2) ,f3  varchar(2) ,f4 varchar(2) )
    insert tb
    select 'a1','b1','c1' union all
    select 'a1','b3','c1' union all
    select 'a1','b1','c1' union all
    select 'a2','b2','c2' union all
    select 'a2','b2','c2' select distinct m.f2,m.f3,m.f4 from tb m , tb n
    where m.f2 = n.f2 and m.f4 = n.f4 and m.f3 <> n.f3drop table tb/*
    f2   f3   f4   
    ---- ---- ---- 
    a1   b1   c1
    a1   b3   c1(所影响的行数为 2 行)
    */
      

  4.   

    you can use group by get your goal