|
本帖最后由 〇〇 于 2017-8-18 07:56 编辑
奇怪,在sqlite下出错了
sqlite> WITH t (colors,cnt) AS (
...> SELECT CAST(c AS VARCHAR2(16)) colors
...> ,1 cnt
...> FROM (SELECT 1 c union select 2 union select 3)
...> UNION ALL
...> SELECT colors||c,cnt+1
...> FROM t,(SELECT 1 c union select 2 union select 3)
...> WHERE cnt<16
...> AND (cnt+1 in (2,3,4) AND c<>substr(colors,-1)
...> OR
...> cnt+1 in (5,9,13) AND c<>substr(colors,cnt+1-4,1)
...> OR c NOT IN (substr(colors,-1),substr(colors,cnt+1-4,1))
...> )
...> )
...> SELECT COUNT(*) FROM t WHERE cnt=16 AND INSTR(colors,'1')>0 AND INSTR(colors,'2')>0 AND INSTR(colors,'3')>0;
Run Time: real 5.172 user 3.875000 sys 0.562500
Error: database or disk is full
原来是没有自动类型转换
sqlite> WITH t (colors,cnt) AS (
...> SELECT CAST(c AS VARCHAR(16)) colors
...> ,1 cnt
...> FROM (SELECT '1' c union select '2' union select '3')
...> UNION ALL
...> SELECT colors||c,cnt+1
...> FROM t,(SELECT '1' c union select '2' union select '3')
...> WHERE cnt<16
...> AND (cnt+1 in (2,3,4) AND c<>substr(colors,-1)
...> OR
...> cnt+1 in (5,9,13) AND c<>substr(colors,cnt+1-4,1)
...> OR c NOT IN (substr(colors,-1),substr(colors,cnt+1-4,1))
...> )
...> )
...> SELECT COUNT(*) FROM t WHERE cnt=16 AND INSTR(colors,'1')>0 AND INSTR(colors,'2')>0 AND INSTR(colors,'3')>0;
Run Time: real 0.078 user 0.078125 sys 0.000000
|
|