我正在尝试做这样的事情
本机SQL:
Select *
from FirstTable ft
right join SecondTable st on (st.ID=ft.ID and ft.fStatus !='b') where ft.fStatus!='b'
总之我只是不想地图FirstTable
数据与SecondTable
当有这样的事情[ft.fStatus !='b']
。但是,发生这种情况时,我想从中获得相应的记录SecondTable
。
我搜索了此with
关键字并找到了关键字,但这对我的情况没有帮助。请查看下面的示例数据以获取任何参考:
FirstTable
fId | fName | fStatus
++++++++++++++++++++++++++++++
1 | Name1 | b
2 | Name2 | b
3 | Name3 | a
2 | Name4 | b
3 | Name5 | b
4 | Name6 | a
4 | Name7 | a
SecondTable
sId | sName
+++++++++++++++++++
1 | Name1
2 | Name2
3 | Name3
4 | Name4
Expected Output :
fId | fName | sId | sName
++++++++++++++++++++++++++++++++++++++++++++
_ | _ | 1 | Name1
_ | _ | 2 | Name2
3 | Name3 | 3 | Name3
4 | Name6 | 4 | Name4
4 | Name7 | 4 | Name4
您需要oneToMany
在Parent Entity
ie中SecondTable
为Child Entity
ie添加映射FirstTable
。例如 :
class FirstTable{
Integer pkColumn;
SecondTable fId ;
String fName ;
String fStatus;
--Getter and Setters
}
class SecondTable{
Integer sId ;
String sName ;
@oneToManny(mappedBy="fId ")
List<FirstTable> firstTable;
--Getter and Setters
}
HQL为您的预期输出:
SELECT ft.fId, ft.fName, st.sId, st.sName FROM SecondTable st
LEFT JOIN st.firstTable ft WITH ft.fStatus != 'b'
WHERE (--other Conditions--)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句