我有三张桌子。Cable
、PhysicalPoint
和{
Cable
包含两个PhysicalPoint
(上坡、下坡)和{Interconnect
有相同PhysicalPoint
的Cable
。我想是用SQL而不是SQL炼金术。在
#cable, physicalpoint and interconnect are sqlalchemy.Table
c = cable.alias('c')
pdh = physicalpoint.alias('pdh')
puh = physicalpoint.alias('puh')
idh = interconnect.alias('idh')
iuh = interconnect.alias('iuh')
j = c.outerjoin(pdh, pdh.c.id==c.c.cab_downhill)\
.outerjoin(puh, puh.c.id==c.c.cab_uphill)
# this is where I don't know what to do...
j2 = outerjoin(idh, pdh, pdh.c.id==idh.c.id)
j3 = outerjoin(iuh, puh, puh.c.id==iuh.c.id)
# this works but how to integrate the two other join ?
db.execute(select(c.c).select_from(j))
我希望这足够全面。。。提前谢谢。在
编辑: 我写的sql查询是这样的:
^{pr2}$
您的编写方式与编写SQL查询的方式完全相同:
相关问题 更多 >
编程相关推荐