存储过程:
create proc getmobile
as
declare @tmp table (mobile1 varchar(20),mobile2 varchar(20))insert @tmp
select top 10 a.mobile,b.mobile from Tab1 a,Tab1 b
where a.home_co=1
and b.home_co=2
and right(rtrim(a.mobile),4)=right(rtrim(a.mobile),4)declare @rNum int
declare @rNum1 intselect @rNum=count(*) from @tmp
set @rNum1=10-@rNum
if @rNum1>0
bugin
     set rowcount @rNum1
    insert @tmp
     select a.mobile,b.mobile from Tab1 a,Tab1 b
      where a.home_co=1
      and b.home_co=2
      and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
      and right(rtrim(a.mobile),3)=right(rtrim(a.mobile),3)
end
else 
   goto theendselect @rNum=count(*) from @tmp
set @rNum1=10-@rNum
if @rNum1>0
bugin
     set rowcount @rNum1
    insert @tmp
     select a.mobile,b.mobile from Tab1 a,Tab1 b
      where a.home_co=1
      and b.home_co=2
      and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
      and right(rtrim(a.mobile),3)<>right(rtrim(a.mobile),3)
      and right(rtrim(a.mobile),2)=right(rtrim(a.mobile),2)
end
else 
   goto theendselect @rNum=count(*) from @tmp
set @rNum1=10-@rNum
if @rNum1>0
bugin
     set rowcount @rNum1
    insert @tmp
     select a.mobile,b.mobile from Tab1 a,Tab1 b
      where a.home_co=1
      and b.home_co=2
      and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
      and right(rtrim(a.mobile),3)<>right(rtrim(a.mobile),3)
      and right(rtrim(a.mobile),2)<>right(rtrim(a.mobile),2)
      and right(rtrim(a.mobile),1)=right(rtrim(a.mobile),1)
end
theend:
    select mobile1 as mobile from @tmp
    union all
    select mobile2 as mobile from @tmpgo
速度不怎么样

解决方案 »

  1.   

    select top 10 * from 
    (select 4 as num, mobile, home_co from tabl1 A left join tabl1 B 
      on right(A.mobile, 4) = right(B.mobile, 4) and A.home_co = 1 and B.home_co = 2
     union all select 3, mobile, home_co from tabl1 A left join tabl1 B 
      on right(A.mobile, 3) = right(B.mobile, 3) and A.home_co = 1 and B.home_co = 2
     union all select 2, mobile, home_co from tabl1 A left join tabl1 B 
      on right(A.mobile, 2) = right(B.mobile, 2) and A.home_co = 1 and B.home_co = 2
     union all select 1, mobile, home_co from tabl1 A left join tabl1 B 
      on right(A.mobile, 1) = right(B.mobile, 1) and A.home_co = 1 and B.home_co = 2)
    order by num desc
      

  2.   

    我感觉可以利用LIKE和TOP用一句SQL实现你的要求
      

  3.   

    SELECT TOP 10 DISTINCT T1.mobile,T2.mobile
      FROM (SELECT * FROM TAB1 WHERE home_co = 1) T1
           (SELECT * FROM TAB1 WHERE home_co = 2) T2
     WHERE RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) 
        OR RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) 
        OR RIGHT(T1.mobile,2) = RIGHT(T2.mobile,2) 
        OR RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1) 
     ORDER BY CASE 
                WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) THEN 1
                WHEN RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) THEN 2
        WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,2) THEN 3
        WHEN RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1) THEN 4
              END
    这个语句的效率不好,而且可能有重复的数据,比如(13701117172,13338887172)(13701117172,13377777172)也就是说13701117172可能会出现两次,你的问题里没有说明一个手机号是否可以同时在多组里出现,如果你不想有这种重复,还要在这个查询基础上继续作一个去重复数据查询,我这里就不细说了
    我这个语句仅仅是一种思路,在效率上不一定可行,要看你的具体的应用,但一般比较大的系统,可能不能使用,但这个语句的好处是可以编写为视图,写程序的思路比较清晰,希望大家继续探讨[email protected]
      

  4.   

    笔误
    CASE 
                WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) THEN 1
                WHEN RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) THEN 2
        WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,2) THEN 3
        WHEN RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1) THEN 4
              END
    修改为
    CASE 
                WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) THEN 1
                WHEN RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) THEN 2
        WHEN RIGHT(T1.mobile,2) = RIGHT(T2.mobile,2) THEN 3
        WHEN RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1) THEN 4
              ENDCASE语句的顺序一定不能错,比如
    CASE
                WHEN RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) THEN 2 
                WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) THEN 1
        WHEN RIGHT(T1.mobile,2) = RIGHT(T2.mobile,2) THEN 3
        WHEN RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1) THEN 4
              END
    这样就错了,这样的话所有的4个匹配的都只会当3个匹配的来排序
      

  5.   

    create table #temp
    (num int,
     am char(20),
     ah int,
     bm char(20),
     bh int)
    declare @row int
    set @row = 0
    while @row < 10
    begin
      insert into #temp
      select top 1 * from 
      (select '4' as num, A.mobile a1, A.home_co a2 , B.mobile b1 , B.home_co b2 from tabl1 A left join tabl1 B 
      on right(A.mobile, 4) = right(B.mobile, 4) and A.home_co = 1 and B.home_co = 2
      union select '3' as num, A.mobile, A.home_co, B.mobile, B.home_co from tabl1 A left join tabl1 B 
      on right(A.mobile, 3) = right(B.mobile, 3) and A.home_co = 1 and B.home_co = 2
      union select '2' as num, A.mobile, A.home_co, B.mobile, B.home_co from tabl1 A left join tabl1 B 
      on right(A.mobile, 2) = right(B.mobile, 2) and A.home_co = 1 and B.home_co = 2
      union select '1' as num, A.mobile, A.home_co, B.mobile, B.home_co from tabl1 A left join tabl1 B 
      on right(A.mobile, 1) = right(B.mobile, 1) and A.home_co = 1 and B.home_co = 2  ) as C
      where not exists (select am from #temp where am = C.a1) and not exists (select bm from #temp where bm = C.b1)
      and C.a1 is not null and C.b1 is not null
      order by C.num desc
      select @row = count(*) from #temp 
    endselect * from #temp
      

  6.   

    用Haiwer(海阔天空)的方法的测试结果:
    13070990000 62500000   
    13189100000 62500000   
    13068780000 62500000   
    13070990001 62500001   
    13189100001 62500001   
    13068780001 62500001   
    13070990002 62500002   
    13189100002 62500002   
    13068780002 62500002   
    13070990003 62500003   
    有出现重复的数据,
    tj_dns(愉快的登山者)
    hillhx(曾经的曾经)
    是不是你们两个的语法有错!
    我这里通不过,小弟愚昧,还望指点.
    因为数据比较多,所以有随机一说了(不随机也没错的)
      

  7.   

    解决方法:create proc getmobile
    as
    declare @tmp table (mobile1 varchar(20),mobile2 varchar(20))declare @rNum int
    declare @rNum1 intset @rNum=0while @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)=right(rtrim(a.mobile),4)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)=right(rtrim(a.mobile),4)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    endif @rNum>=10 
       goto theendwhile @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
    and right(rtrim(a.mobile),3)=right(rtrim(a.mobile),3)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
    and right(rtrim(a.mobile),3)=right(rtrim(a.mobile),3)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    endif @rNum>=10 
       goto theendwhile @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(a.mobile),3)
    and right(rtrim(a.mobile),2)=right(rtrim(a.mobile),2)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(a.mobile),3)
    and right(rtrim(a.mobile),2)=right(rtrim(a.mobile),2)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    endif @rNum>=10 
       goto theendwhile @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(a.mobile),3)
    and right(rtrim(a.mobile),2)<>right(rtrim(a.mobile),2)
    and right(rtrim(a.mobile),1)=right(rtrim(a.mobile),1)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(a.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(a.mobile),3)
    and right(rtrim(a.mobile),2)<>right(rtrim(a.mobile),2)
    and right(rtrim(a.mobile),1)=right(rtrim(a.mobile),1)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    end
    theend:
        select mobile1 as mobile from @tmp
        union all
        select mobile2 as mobile from @tmpgo
      

  8.   

    TO: Haiwer(海阔天空)
    运行到
    begin
    insert @tmp
    时一直运行,没反应了.
    declare @tmp table (mobile1 varchar(20),mobile2 varchar(20))declare @rNum int
    declare @rNum1 intset @rNum=0while @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)=right(rtrim(a.mobile),4)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    有问题吗?
      

  9.   

    表中数据
    13001112222 2
    13001113333 2
    13001114444 2
    13011112222 2
    13011115555 2
    13011116666 2
    13011117777 2
    13011118888 2
    13011119999 2
    13021112222 2
    13021112372 2
    13021113333 2
    13901112222 1
    13901113333 1
    13901114444 1
    13901115555 1
    13901116666 1
    13901117172 1
    13901117777 1
    13901118888 1
    13901119999 1
    13911112222 1
    13911113333 1
    查询语句
    SELECT TOP 10 MOB1,RIGHT(MOB2,LEN(MOB2)-1) AS MOB3,MOB2
      FROM (SELECT T1.mobile AS MOB1,MIN(CASE
                                           WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) THEN 'A'+T2.mobile
                                           WHEN RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) THEN 'B'+T2.mobile
                                           WHEN RIGHT(T1.mobile,2) = RIGHT(T2.mobile,2) THEN 'C'+T2.mobile
                                           WHEN RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1) THEN 'D'+T2.mobile
                                         END) AS MOB2
              FROM (SELECT * FROM TAB1 WHERE home_co = 1) T1,
                   (SELECT * FROM TAB1 WHERE home_co = 2) T2
             WHERE RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) 
                OR RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) 
                OR RIGHT(T1.mobile,2) = RIGHT(T2.mobile,2) 
                OR RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1)
             GROUP BY T1.mobile) T3
    查询结果
    13901112222 13001112222 A13001112222
    13901113333 13001113333 A13001113333
    13901114444 13001114444 A13001114444
    13901115555 13011115555 A13011115555
    13901116666 13011116666 A13011116666
    13901117172 13021112372 C13021112372
    13901117777 13011117777 A13011117777
    13901118888 13011118888 A13011118888
    13901119999 13011119999 A13011119999
    13911112222 13001112222 A13001112222昨天不好意思,我给你的SQL我自己都没有实验,其实那只是个思路,的确执行不了。我今天特意创建了个表测过了,应该没什么问题。
    这个查询我已经将重复数据用GROUP BY语句的方式去掉了。
    CASE语句中的'A'+T2.mobile部分是为了排序使用,也就是说如果末尾4个数字相同的增加一个'A',3个数字相同的增加一个'B'...以次类推,最后再找到最小值,因为A开头的字符串一定小于B开头的字符串,所以最小值就是字符相同量最大的T2.mobile,我这里使用的这个方法稍微有点取巧,并不正统,你最好可以换一种方式实现。
      

  10.   

    SELECT TOP 10 MOB1,RIGHT(MOB2,LEN(MOB2)-1) AS MOB3,MOB2
      FROM (SELECT T1.mobile AS MOB1,MIN(CASE
                                           WHEN RIGHT(T1.mobile,4) = RIGHT(T2.mobile,4) THEN 'A'+T2.mobile
                                           WHEN RIGHT(T1.mobile,3) = RIGHT(T2.mobile,3) THEN 'B'+T2.mobile
                                           WHEN RIGHT(T1.mobile,2) = RIGHT(T2.mobile,2) THEN 'C'+T2.mobile
                                           WHEN RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1) THEN 'D'+T2.mobile
                                         END) AS MOB2
              FROM (SELECT * FROM TAB1 WHERE home_co = 1) T1,
                   (SELECT * FROM TAB1 WHERE home_co = 2) T2
             WHERE RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1)
             GROUP BY T1.mobile) T3
    忽然发现我语句里的OR全都没用,真是很低级的错误,把它们全去了吧就保留一个RIGHT(T1.mobile,1) = RIGHT(T2.mobile,1)
      

  11.   

    数据
    13001112222 2
    13001113333 2
    13001114444 2
    13011112222 2
    13011115555 2
    13011116666 2
    13011117777 2
    13011118888 2
    13011119999 2
    13021112222 2
    13021112372 2
    13021113333 2
    13901112222 1
    13901113333 1
    13901114444 1
    13901115555 1
    13901116666 1
    13901117172 1
    13901117777 1
    13901118888 1
    13901119999 1
    13911112222 1
    13911113333 1查询语句
    SELECT TOP 10 RIGHT(MOB1,LEN(MOB1)-1),RIGHT(MOB2,LEN(MOB2)-1)
      FROM (SELECT MIN(CASE
                         WHEN RIGHT(MOB1,4) = RIGHT(MOB2,4) THEN 'A'+MOB1
                         WHEN RIGHT(MOB1,3) = RIGHT(MOB2,3) THEN 'B'+MOB1
                         WHEN RIGHT(MOB1,2) = RIGHT(MOB2,2) THEN 'C'+MOB1
                         WHEN RIGHT(MOB1,1) = RIGHT(MOB2,1) THEN 'D'+MOB1
                       END) AS MOB1,MOB2
              FROM (SELECT MOB1,MIN(CASE
                                      WHEN RIGHT(MOB1,4) = RIGHT(MOB2,4) THEN 'A'+MOB2
                                      WHEN RIGHT(MOB1,3) = RIGHT(MOB2,3) THEN 'B'+MOB2
                                      WHEN RIGHT(MOB1,2) = RIGHT(MOB2,2) THEN 'C'+MOB2
                                      WHEN RIGHT(MOB1,1) = RIGHT(MOB2,1) THEN 'D'+MOB2
                                    END) AS MOB2
                      FROM (SELECT mobile AS MOB1 FROM TAB1 WHERE home_co = 1) T1,
                           (SELECT mobile AS MOB2 FROM TAB1 WHERE home_co = 2) T2
                     WHERE RIGHT(MOB1,1) = RIGHT(MOB2,1)
                     GROUP BY MOB1) T3
             GROUP BY MOB2) T4
             
    结果
    13901112222 13001112222
    13901113333 13001113333
    13901114444 13001114444
    13901115555 13011115555
    13901116666 13011116666
    13901117777 13011117777
    13901118888 13011118888
    13901119999 13011119999
    13901117172 13021112372
    这种方法可以去掉所有重复的数据,我原先提供的方法中产生的是有重复数据的结果,再进行一次GROUP BY就可以去掉所有的重复数据了
      

  12.   

    这次改对了:
    原因:
    and right(rtrim(a.mobile),4)=right(rtrim(a.mobile),4)
    --->
    and right(rtrim(a.mobile),4)=right(rtrim(B.mobile),4)
    create proc getmobile
    as
    declare @tmp table (mobile1 varchar(20),mobile2 varchar(20))
    declare @rNum int
    declare @rNum1 intset @rNum=0while @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)=right(rtrim(B.mobile),4)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)=right(rtrim(B.mobile),4)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    endif @rNum>=10 
       goto theendwhile @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(B.mobile),4)
    and right(rtrim(a.mobile),3)=right(rtrim(B.mobile),3)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(B.mobile),4)
    and right(rtrim(a.mobile),3)=right(rtrim(B.mobile),3)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    endif @rNum>=10 
       goto theendwhile @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(B.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(B.mobile),3)
    and right(rtrim(a.mobile),2)=right(rtrim(B.mobile),2)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(B.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(B.mobile),3)
    and right(rtrim(a.mobile),2)=right(rtrim(B.mobile),2)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    endif @rNum>=10 
       goto theendwhile @rNum<10 and exists (
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(B.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(B.mobile),3)
    and right(rtrim(a.mobile),2)<>right(rtrim(B.mobile),2)
    and right(rtrim(a.mobile),1)=right(rtrim(B.mobile),1)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    )
    begin
    insert @tmp
    select top 1 a.mobile,b.mobile from Tab1 a,Tab1 b
    where a.home_co=1
    and b.home_co=2
    and right(rtrim(a.mobile),4)<>right(rtrim(B.mobile),4)
    and right(rtrim(a.mobile),3)<>right(rtrim(B.mobile),3)
    and right(rtrim(a.mobile),2)<>right(rtrim(B.mobile),2)
    and right(rtrim(a.mobile),1)=right(rtrim(B.mobile),1)
    and not exists (
     select * from @tmp x where x.mobile1=a.mobile or x.mobile2=b.mobile
    )
    order by newid()
    set @rNum=@rNum+1
    end
    theend:
        select * from @tmp    select mobile1 as mobile from @tmp
        union all
        select mobile2 as mobile from @tmpgo
      

  13.   

    create table Tab1(
    mobile varchar(20),
    home_co int
    )insert tab1
    select
    '13001112222', 2 
    union all
    select
    '13001113333', 2
    union all
    select
    '13001114444' ,2
    union all
    select
    '13011112122', 2
    union all
    select
    '13011115555' ,2
    union all
    select
    '13011116666', 2
    union all
    select
    '13011117777' ,2
    union all
    select
    '13011118888', 2
    union all
    select
    '13011119999' ,2
    union all
    select
    '13021112221', 2
    union all
    select
    '13021112372' ,2
    union all
    select
    '13021117333', 2
    union all
    select
    '13901112222' ,1
    union all
    select
    '13901118333', 1
    union all
    select
    '13901111444' ,1
    union all
    select
    '13901115755', 1
    union all
    select
    '13901116466' ,1
    union all
    select
    '13901117172', 1
    union all
    select
    '13901117747' ,1
    union all
    select
    '13901118588', 1
    union all
    select
    '13901119599' ,1
    union all
    select
    '13911112022', 1
    union all
    select
    '13911113033' ,1
    结果:mobile1              mobile2              
    -------------------- -------------------- 
    13901112222          13001112222
    13901118333          13021117333
    13901111444          13001114444
    13911112022          13011112122
    13901115755          13011115555
    13911113033          13001113333
    13901118588          13011118888
    13901119599          13011119999
    13901116466          13011116666
    13901117172          13021112372(所影响的行数为 10 行)相同位数:
    4
    3
    3
    2
    2
    2
    2
    2
    2
    2
      

  14.   

    欣赏 Haiwer(海阔天空) 的语句,象看散文诗一样,一个字:                       爽!