|
newkid 发表于 2012-5-9 21:36 ![]()
WITH t AS (
SELECT LEVEL n FROM DUAL CONNECT BY LEVEL
人肉思路和问题2差不多
先看前三个数字
with t as (SELECT LEVEL n FROM DUAL CONNECT BY LEVEL<=4)
,s as (select t1.n||t2.n||t3.n||t4.n p from t t1,t t2, t t3, t t4
where abs(t1.n-t2.n)=1 and abs(t2.n-t3.n)=1 and abs(t3.n-t4.n)=1)
select substr(p,1,3), count(*) from s group by substr(p,1,3)
/
SUBSTR(P,1,3) COUNT(*)
121 1
123 2
212 2
232 2
234 1
321 1
323 2
343 2
432 2
434 1
再看后三个数字
with t as (SELECT LEVEL n FROM DUAL CONNECT BY LEVEL<=4)
,s as (select t1.n||t2.n||t3.n||t4.n p from t t1,t t2, t t3, t t4
where abs(t1.n-t2.n)=1 and abs(t2.n-t3.n)=1 and abs(t3.n-t4.n)=1)
--select substr(p,1,3), count(*) from s group by substr(p,1,3)
select substr(p,2), count(*) from s group by substr(p,2)
SUBSTR(P,2) COUNT(*)
121 1
123 1
212 2
232 2
234 2
321 2
323 2
343 2
432 1
434 1
然后想想怎么合并 |
|