select top 1 a.某个字段 as 某个字段1,b.某个字段 as 某个字段2
from 表 a,表 b
order by abs(a.某个字段-b.某个字段)

解决方案 »

  1.   

    select top 1 a.某个字段 as 某个字段1,b.某个字段 as 某个字段2
    from 表 a,表 b
    where a,id<>b.id
    order by abs(a.某个字段-b.某个字段)
      

  2.   

    --比如说,前3位相同的
    select * from 表 a
    where exists(select * from 表 where left(字段,3)=left(a.字段,3))
      

  3.   

    to  zjcxc(邹建) 不行啊!显示的都不和要求!我的字段是varchar(50)的类型
      

  4.   

    --少限制了一个条件select * from 表 a
    where exists(select * from 表 where 字段<>a.字段 and left(字段,3)=left(a.字段,3))
    order by 字段
      

  5.   

    --测试数据
    declare @t table(a varchar(50))
    insert @t select '380695261'
    union all select '411275303'
    union all select '250928829'
    union all select '360831343'
    union all select '411273648'
    union all select '286644423'
    union all select '286644423'
    union all select '380693652'
    union all select '312772583'
    union all select '411271267'
    union all select '312772511'
    union all select '373276544'
    union all select '363951636'
    union all select '305065994'
    union all select '411269945'
    union all select '369506652'
    union all select '395673923'
    union all select '254133880'
    union all select '383701153'
    union all select '363950562'
    union all select '344210400'
    union all select '250922672'
    union all select '254130526'
    union all select '373274842'--查询
    select * from @t a
    where exists(select * from @t where a<>a.a and left(a,3)=left(a.a,3))
    order by a/*--测试结果a                                                  
    -------------------------------------------------- 
    250922672
    250928829
    254130526
    254133880
    312772511
    312772583
    363950562
    363951636
    373274842
    373276544
    380693652
    380695261
    411269945
    411271267
    411273648
    411275303(所影响的行数为 16 行)
    --*/