我尝试使用重复属性连接这些表:
表格1:
r_object_id codes
... 1,2,3,4,5
... 7,6,3,4,5
... 1,5,4,2,3
其中codes
属性是重复属性。
表2:
r_object_id name code
... hello 1
... aba 2
... father 3
... mother 4
... hello2 5
... hello3 6
... hello4 7
我想要这样的结果:
table1.r_object_id names
... hello,aba,father,mother,hello2
我能做什么?
这在一个DQL查询中是不可能的。但是你有一些选择如何解决它。
1)使用一个DQL,但每个重复值有一行:
SELECT DISTINCT t1.r_object_id, t2.name FROM table1 t1, table2 t2 WHERE t1.codes = t2.code ENABLE(ROW_BASED)
结果将是这样的:
r_object_id name
0900ad1234567890 hello
0900ad1234567890 aba
0900ad1234567890 father
0900ad1234567890 mother
0900ad1234567890 hello2
0900ad1234567891 father
0900ad1234567891 mother
...
2)在应用程序中配对值 - 例如使用Java。从一个查询中选择table2中的所有记录并将它们存储到Map<String, String> codeTable
中,其中code
属性作为键,name
属性作为值。然后通过另一个查询从table1中选择记录,并将重复属性(代码)中的值与来自codeTable
映射的值配对。