首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

求一个SQL语句,达人帮帮忙了

2011-12-07 
求一个SQL语句,达人帮帮忙了,在线等SELECT缴款人账号FROMzh331GROUPBY缴款人账号HAVINGCOUNT(SUBSTRING(缴

求一个SQL语句,达人帮帮忙了,在线等
SELECT   缴款人账号
FROM   zh331
GROUP   BY   缴款人账号
HAVING   COUNT(SUBSTRING(缴款人账号,   2,   5))   > =   2

求缴款人账号从第二位开始到第六位的数字重复数大于等于2的,上面的是错的,只是为了跟大家表述清楚,达人帮忙了,在线等,急!


[解决办法]
SELECT SUBSTRING(缴款人账号, 2, 5)
FROM zh331
GROUP BY SUBSTRING(缴款人账号, 2, 5)
HAVING COUNT(*)> = 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

不知道我猜到你想要的结果了没有
[解决办法]

探讨
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)
已经试过了,应该可以满足楼主的需求

[解决办法]
探讨
引用:
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', 如上面红色部分 
 

這個應該可以啊!

[解决办法]
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

热点排行