执行查询目标表,该表必须验证源表中的2个值
SELECT ID_MAQ, NOM_EMP, DES_MOD, DES_JGO, DES_MAR FROM M_MAQ
INNER JOIN M_EMP ON M_MAQ.ID_EMP = M_EMP.ID_EMP
INNER JOIN A_MOD ON M_MAQ.ID_MOD = A_MOD.ID_MOD AND M_MAQ.ID_MAR = A_MOD.ID_MAR
INNER JOIN A_JGO ON M_MAQ.ID_JGO = A_JGO.ID_JGO AND M_MAQ.ID_MAR = A_JGO.ID_MAR AND M_MAQ.ID_MOD = A_JGO.ID_MOD
INNER JOIN M_MAR ON M_MAQ.ID_MAR = M_MAR.ID_MAR
ORDER BY ID_MAQ ASC
我有那个SQL查询,如何使用django ORM做到呢?
我尝试使用select_related
,但没有获得正确的值,因为查询ON M_MAQ.ID_MOD = A_MOD.ID_MOD AND M_MAQ.ID_MAR = A_MOD.ID_MAR
需要根据表M_MAQ
的值与M_MOD
ID_MOD
的值进行比较和ID_MAR
。
有人知道他怎么做吗?