--try
DECLARE @t TABLE (A CHAR(1),B INT ,C DECIMAL(18,1))
INSERT INTO @t SELECT 'A', 0, 0.9 UNION ALL 
SELECT 'A', 1, 0.8 UNION ALL SELECT
'A', 2, 0.9 UNION ALL SELECT
'A', 3, 0.9 UNION ALL SELECT
'A', 4, 0.9 UNION ALL SELECT
'A', 5, 0.9 UNION ALL SELECT
'A', 6, 0.9 UNION ALL SELECT
'A', 7, 0.10 UNION ALL SELECT
'A', 8, 0.9SELECT * FROM @t a WHERE NOT EXISTS(SELECT 1 FROM @t WHERE a.B=B+1 AND a.C=C)

解决方案 »

  1.   

    select 

    from 
    @T t  
    where 
    exists(select 1 from @T where 編碼=t.編碼 and 值!=t.值 and 序號=t.序號-1  )
    or
    序號=0
      

  2.   

    贴一个用临时表实现的思路,楼主看一下是不是这样..declare @T table(編碼 nvarchar(2) ,          序號  int,             值 numeric(10,2))
    insert @T select 'A',                     0,                       0.9 
    insert @T select 'A',                     1,                       0.8 
    insert @T select 'A',                     2,                       0.9 
    insert @T select 'A',                     3,                       0.9 
    insert @T select 'A',                     4 ,                      0.9 
    insert @T select 'A',                     5,                       0.9 
    insert @T select 'A',                     6,                       0.9 
    insert @T select 'A',                     7,                       0.10 
    insert @T select 'A',                     8,                       0.9 
    select 

    from 
    @T t  
    where 
    exists(select 1 from @T where 編碼=t.編碼 and 值!=t.值 and abs(序號-t.序號)!>1  )go
    select 
    *
     from 
    # t
    where 
    not exists(select 1 from # where 編碼=t.編碼 and 序號=(select max(序號) from # where 序號<t.序號) and 值=t.值)編碼   序號          值            
    ---- ----------- ------------ 
    A    0           .90
    A    1           .80
    A    2           .90
    A    7           .10
    A    8           .90(所影响的行数为 5 行)
      

  3.   


    ----- 序號 不重复时,直接这样用
    declare @T table(編碼 nvarchar(2) ,          序號  int,             值 numeric(10,2))
    insert @T select 'A',                     0,                       0.9 
    insert @T select 'A',                     1,                       0.8 
    insert @T select 'A',                     2,                       0.9 
    insert @T select 'A',                     3,                       0.9 
    insert @T select 'A',                     4 ,                      0.9 
    insert @T select 'A',                     5,                       0.9 
    insert @T select 'A',                     6,                       0.9 
    insert @T select 'A',                     7,                       0.10 
    insert @T select 'A',                     8,                       0.9 select 
        *    
     from 
        @T t
    where 
        not exists(select 1 from @T where 編碼=t.編碼 and 序號=(select max(序號) from @T where 序號<t.序號) and 值=t.值)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)編碼   序號          值            
    ---- ----------- ------------ 
    A    0           .90
    A    1           .80
    A    2           .90
    A    7           .10
    A    8           .90(所影响的行数为 5 行)
      

  4.   


    ----- 編碼相同时,序號 不重复时,直接这样用
    declare @T table(編碼 nvarchar(2) ,          序號  int,             值 numeric(10,2))
    insert @T select 'A',                     0,                       0.9 
    insert @T select 'A',                     1,                       0.8 
    insert @T select 'A',                     2,                       0.9 
    insert @T select 'A',                     3,                       0.9 
    insert @T select 'A',                     4 ,                      0.9 
    insert @T select 'A',                     5,                       0.9 
    insert @T select 'A',                     6,                       0.9 
    insert @T select 'A',                     7,                       0.10 
    insert @T select 'A',                     8,                       0.9 select 
        *    
     from 
        @T t
    where 
        not exists(select 1 from @T where 編碼=t.編碼 and 序號=(select max(序號) from @T where 序號<t.序號) and 值=t.值)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)
    (所影响的行数为 1 行)編碼   序號          值            
    ---- ----------- ------------ 
    A    0           .90
    A    1           .80
    A    2           .90
    A    7           .10
    A    8           .90(所影响的行数为 5 行)
      

  5.   

    基本上就是roy的写法了.DECLARE @t TABLE(code VARCHAR(10),idx INT,value DECIMAL(10,1))
    INSERT @t SELECT 'A'        ,             0,                       0.9 
    UNION ALL SELECT 'A'       ,              1 ,                      0.8 
    UNION ALL SELECT 'A'      ,               2  ,                     0.9 
    UNION ALL SELECT 'A'     ,                3   ,                    0.9 
    UNION ALL SELECT 'A'    ,                 4    ,                   0.9 
    UNION ALL SELECT 'A'   ,                  5     ,                  0.9 
    UNION ALL SELECT 'A'  ,                   6      ,                 0.9 
    UNION ALL SELECT 'A' ,                    7       ,                0.10
    UNION ALL SELECT 'A',                     8        ,               0.9
    SELECT * FROM @t a
    WHERE NOT EXISTS(SELECT 1 FROM @t WHERE code=a.code AND value=a.value AND idx=a.idx-1)
      

  6.   

    declare @T table(編碼 nvarchar(2) ,          序号  int,             值 numeric(10,2))
    insert @T select 'A',                     0,                       0.9 
    insert @T select 'A',                     1,                       0.8 
    insert @T select 'A',                     2,                       0.9 
    insert @T select 'A',                     3,                       0.9 
    insert @T select 'A',                     4 ,                      0.9 
    insert @T select 'A',                     5,                       0.9 
    insert @T select 'A',                     6,                       0.9 
    insert @T select 'A',                     7,                       0.10 
    insert @T select 'A',                     8,                       0.9 
    select * from @t a where not exists(select 1 from @t where a.序号=序号+1 and 值=a.值)