要求将列a中所缺序号提取出来,如0701-0708中没有 0703, 0901-0911中没有0909 。
列a
0701
0702
0704
0705
0706
0707
0708
0801
0802
0803
0804
0805
0806
0807
0901
0902
0903
0904
0905
0906
0907
0908
0910
0911

解决方案 »

  1.   

    -- =========================================
    -- -----------t_mac 小编-------------
       ---希望有天成为大虾---- 
    -- =========================================IF OBJECT_ID('tb') IS NOT NULL
      DROP TABLE tb
    GO
    CREATE TABLE tb(a varchar(10) )
    go
    insert tb SELECT 
    0701 UNION ALL SELECT 
    0702 UNION ALL SELECT 
    0704 UNION ALL SELECT 
    0705 UNION ALL SELECT 
    0706 UNION ALL SELECT 
    0707 UNION ALL SELECT 
    0708 UNION ALL SELECT 
    0801 UNION ALL SELECT 
    0802 UNION ALL SELECT 
    0803 UNION ALL SELECT 
    0804 UNION ALL SELECT 
    0805 UNION ALL SELECT 
    0806 UNION ALL SELECT 
    0807 UNION ALL SELECT 
    0901 UNION ALL SELECT 
    0902 UNION ALL SELECT 
    0903 UNION ALL SELECT 
    0904 UNION ALL SELECT 
    0905 UNION ALL SELECT 
    0906 UNION ALL SELECT 
    0907 UNION ALL SELECT 
    0908 UNION ALL SELECT 
    0910 UNION ALL SELECT 
    0911
    go
    select right(a+1+'10000',4)
    from tb 
    where a+1 not in(select a from tb ) and a+2 in(select a from tb)go
    /*------------
    --------
    0703
    0909
    -------*/
      

  2.   

    如果缺好定义成上下都有select a.a+1 as 缺号
    from tb a
    where not exists (select 1 from tb where a=a.a+1)
    and exists (select 1 from tb where a=a.a+2)
      

  3.   


    select t.tt from 
    (select a.aa+tb2.b tt from (select distinct left(a,2) aa from tb) a  cross join 
    (
    select '01' b union all 
    select '02' union all 
    select '03' union all 
    select '04' union all 
    select '05' union all 
    select '06' union all 
    select '07' union all 
    select '08' union all 
    select '09' union all 
    select '10' 
    ) tb2 ) t
    left join tb on t.tt=tb.a where tb.a is null
      

  4.   


    我试了一下,如果-- 0704 UNION ALL SELECT 这句注释掉的话,就是0704这个数字也没有,好像结果就不对了