我尝试使用重复属性来连接这些表:
表1 :
codes
r_object_id name code
... hello 1
... aba 2
... father 3
... mother 4
... hello2 5
... hello3 6
... hello4 7
属性是重复属性。
表2 :
table1.r_object_id names
... hello,aba,father,mother,hello2
我想要这样的结果:
Viewsets
我该怎么办?
答案 0 :(得分:1)
这在一个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 中选择记录,并将重复属性( codes )中的值与codeTable
映射中的值配对。