我有一个简单的查询:
select key, name from cities
这给了我这样的价值观:
11 | Chicago
21 | New York
31 | Boston
我需要做的是在SQL或Java中创建所有可能组合的哈希值,以便在结束时接收此结果:
11 | Chicago
21 | New York
31 | Boston
32 | Chicago/New York
42 | Chicago/Boston
52 | New York/Boston
63 | Chicago/New York/Boston
有什么想法吗?
答案 0 :(得分:0)
这不完美,但可能是一个开始:
首先我创建了一个函数:
create or replace function sum_string(str in varchar2) return number is
Result number;
begin
execute immediate 'select ' || str || ' from dual'
into result;
return(Result);
end sum_string;
/
然后是查询(your_table
是你的表)
with jwt as (
select t1.key k1, t1.name n1, t2.key k2, t2.name n2, t1.key + t2.key jkey
from your_table t1
left outer join (select key, name
from your_table
union all
select 0 "key", null "name" from dual) t2 on t1.key <>
t2.key
)
select jkey, max(aaa.pth)
from (select sys_connect_by_path(t.n1, '/') pth,
sum_string(ltrim(sys_connect_by_path(t.k1, '+'), '+')) jkey
from jwt t
start with t.k2 = 0
connect by nocycle prior k1 = k2) aaa
group by jkey;