SELECT 缴款人账号
FROM zh331
GROUP BY 缴款人账号
HAVING COUNT(SUBSTRING(缴款人账号, 2, 5)) >= 2求缴款人账号从第二位开始到第六位的数字重复数大于等于2的,上面的是错的,只是为了跟大家表述清楚,达人帮忙了,在线等,急!

解决方案 »

  1.   

    SELECT SUBSTRING(缴款人账号, 2, 5)
    FROM zh331
    GROUP BY SUBSTRING(缴款人账号, 2, 5)
    HAVING COUNT(*)>= 2有问题再说!
      

  2.   

    SELECT 缴款人账号
    FROM (
    SELECT 缴款人账号,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '0' || SUBSTRING(缴款人账号, 2, 5), '0'), NULL, 0, 0, 0, 1, 0, 1) AS ZERO,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '1' || SUBSTRING(缴款人账号, 2, 5), '1'), NULL, 0, 0, 0, 1, 0, 1) AS ONE,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '2' || SUBSTRING(缴款人账号, 2, 5), '2'), NULL, 0, 0, 0, 1, 0, 1) AS TWO,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '3' || SUBSTRING(缴款人账号, 2, 5), '3'), NULL, 0, 0, 0, 1, 0, 1) AS THREE,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '4' || SUBSTRING(缴款人账号, 2, 5), '4'), NULL, 0, 0, 0, 1, 0, 1) AS FOUR,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '5' || SUBSTRING(缴款人账号, 2, 5), '5'), NULL, 0, 0, 0, 1, 0, 1) AS FIVE,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '6' || SUBSTRING(缴款人账号, 2, 5), '6'), NULL, 0, 0, 0, 1, 0, 1) AS SIX,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '7' || SUBSTRING(缴款人账号, 2, 5), '7'), NULL, 0, 0, 0, 1, 0, 1) AS SEVEN,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '8' || SUBSTRING(缴款人账号, 2, 5), '8'), NULL, 0, 0, 0, 1, 0, 1) AS EIGHT,
           DECODE(TRANSLATE(SUBSTRING(缴款人账号, 2, 5), '9' || SUBSTRING(缴款人账号, 2, 5), '9'), NULL, 0, 0, 0, 1, 0, 1) AS NINE
    FROM zh331
          )
    WHERE ZERO + ONE + TWO + THREE + FOUR + FIVE + SIX + SEVEN + EIGHT + NINE > 0不知道我猜到你想要的结果了没有
      

  3.   

    select 缴款人账号 
      from zh331
     where substr(缴款人账号,2,5) = 
           (select m 
          from (select a,substr(缴款人账号,2,5) m
                      from zh331)
             group by m
            having count(m) >= 2)
    已经试过了,应该可以满足楼主的需求
      

  4.   

    select 缴款人账号 
      from zh331 
    where substr(缴款人账号,2,5) in 
          (select m 
          from (select a,substr(缴款人账号,2,5) m 
                      from zh331) 
            group by m 
            having count(m) >= 2) 又考虑了一下,'=' 应该该作'in', 如上面红色部分 
      

  5.   

    楼上的答案感觉比较合适,ORACLE 10G 好像没有substring() 其他不知道有没有
      

  6.   

    不是substring()  是substr()!!!
      

  7.   

    你的意思應該是這樣吧!
    select 缴款人账号 from
    (
    select 缴款人账号, substr(缴款人账号,2,1) s2,substr(缴款人账号,3,1) s3,substr(缴款人账号,4,1) s4,substr(缴款人账号,5,1) s5,substr(缴款人账号,6,1) s6 
    from temp1
    )
    where s2  in (s3,s4,s5,s6) or s3 in (s2,s4,s5,s6) or s4 in (s2,s3,s5,s6) or s5 in (s2,s3,s4,s6)
      or s6 in (s2,s3,s4,s5)
    缴款人账号从第二位开始到第六位的数字重复数大于等于2的
    就是如where 子句中的條件了!
      

  8.   

    SELECT   SUBSTR(缴款人账号,   2,   5) 
    FROM   zh331 
    GROUP   BY   SUBSTR(缴款人账号,   2,   5) 
    HAVING   COUNT(*)> =   2 
      

  9.   

    select 缴款人账号 
      from zh331 
    where substr(缴款人账号,2,5) in 
          (select m 
          from (select a,substr(缴款人账号,2,5) m 
                      from zh331) 
            group by m 
            having count(m) >= 2) 
      

  10.   


    这个应该是最满足于需求的 1楼的没有回答楼主的意思,他最后想要查出的结果是帐号,而不是SUBSTR后的结果
      

  11.   

    我抛出一个问题,如果想要得到“缴款人账号从第二位开始到第六位的数字重复数大于等于2的”,我的意思是假如帐号是"20011145”,那么substr(帐号,2,7)=01114 ,那么1的个数有3个,如何统计这些帐号呢————即这个帐号3——7中有3个相同数字的帐号
      

  12.   

    where instr( substr( id, 3,1),  substr( id, 3,4) ) >0
    or    instr( substr( id, 4,1),  substr( id, 4,3) ) >0
    or    instr( substr( id, 5,1),  substr( id, 6,2) ) >0
    or    instr( substr( id, 6,1),  substr( id, 7,1) ) >0
      

  13.   

    where instr( substr( id, 3,1),  substr( id, 3,4) ) >0
    or    instr( substr( id, 4,1),  substr( id, 4,3) ) >0
    or    instr( substr( id, 5,1),  substr( id, 6,2) ) >0
    or    instr( substr( id, 6,1),  substr( id, 7,1) ) >0
      

  14.   

    where instr( substr( id, 3,1),  substr( id, 3,4) ) >0
    or    instr( substr( id, 4,1),  substr( id, 4,3) ) >0
    or    instr( substr( id, 5,1),  substr( id, 6,2) ) >0
    or    instr( substr( id, 6,1),  substr( id, 7,1) ) >0
      

  15.   

    select 缴款人账号 
      from zh331 
    where substr(缴款人账号,2,5) in 
          (select m 
          from (select a,substr(缴款人账号,2,5) m 
                      from zh331) 
            group by m 
            having count(m) >= 2) 
      

  16.   

    where instr( substr( id, 3,1),  substr( id, 3,4) ) >0
    or    instr( substr( id, 4,1),  substr( id, 4,3) ) >0
    or    instr( substr( id, 5,1),  substr( id, 6,2) ) >0
    or    instr( substr( id, 6,1),  substr( id, 7,1) ) >0