我有3张桌子。 Cable
,PhysicalPoint
和Interconnect
。
Cable
包含两个PhysicalPoint
(上坡,下坡)和Interconnect
包含一个PhysicalPoint。我想要求Cable
与PhysicalPoint
共有Interconnect
的所有#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有关,但不是sqlalchemy。
SELECT c.*
FROM cable c
LEFT JOIN physicalpoint pdh ON (pdh.id = c.cab_downhill)
LEFT JOIN physicalpoint puh ON (puh.id = c.cab_uphill)
LEFT JOIN interconnect idh ON (idh.id = pdh.id)
LEFT JOIN interconnect iuh ON (iuh.id = puh.id)
WHERE idh.id='XXXX' OR iuh.id='XXXX'
我希望这很全面......提前谢谢。
编辑: 我写的sql查询是这样的:
Sensor
答案 0 :(得分:0)
您使用与编写SQL查询完全相同的方式编写它:
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
SHELL=/bin/bash
* * * * * /opt/monitor/monitor.sh >> /var/log/monitor.log 2>&1
0 3 * * * /opt/monitor/monitor-log-clean.sh >> /var/log/monitor.log 2>&1