db2递归问题请教
关于在db2中的递归问题
比如我有个表slj_test_005 col_1 –代码字段,col_2 –表示col_1的父级,col_3 –表示col_1所属级别
如果表中有数据
COL_1COL_2COL_3
10011
10010110012
10010210012
100101011001013
100102011001023
10021
10020110022
10020210022
如果:
with tmptab(col_3,col_1)as
(
select col_3,col_1 from slj_test_005 --where col_3 = 3
union all
select b.col_3,b.col_1
from tmptab a, slj_test_005 b
where a.col_1 = char(b.col_3)
)select * from tmptab;
则出来的结果:
COL_3COL_1
11001
2100101
2100102
310010101
310010102
310010201
310010202
11002
2100201
2100202
如果我想得到的结果是
COL_3COL_1
11001
2100101
310010101
310010102
2100102
310010201
310010202
11002
2100201
2100202
该怎么写啊?
[解决办法]
如果对结果的col_1排序其结果如何呢?
[解决办法]
select * from tmptab order by col_1