SQL从一个表web2py中左连接两次
如何做这件事? 我有两张桌子
表格1:
-id
-table2_id_1
-table2_id_2
表2:
-id
-table3_id
表3:
-id
-table4_id
-table5_id
-table6_id
表4,表5和表6:
-id
-name
-date
主表是Table1
db(db.Table1).select()
我需要连接两次Table2(colums)中的女巫我需要连接Table3(在每个table2_id_1和table2_id_2字段中table3_id是等于),比连接Table4,Table5,Table6
我不知道,如果我真的得到了你想要做的事情,但是如果你只是想根据id来加入表格,那么应该这样做:
SELECT *
FROM table1 a JOIN table2 b ON (a.table2_id_1 = b.id) JOIN
table2 c ON (a.table2_id_2 = c.id) JOIN
table3 d ON (b.table3_id = d.id) JOIN
table3 e ON (c.table3_id = e.id) JOIN
table4 f ON (d.table4_id = f.id) JOIN
table5 g ON (d.table5_id = g.id) JOIN
table6 h ON (d.table6_id = h.id) JOIN
table4 i ON (e.table4_id = i.id) JOIN
table5 j ON (e.table5_id = j.id) JOIN
table6 k ON (e.table6_id = k.id)
链接地址: http://www.djcxy.com/p/94299.html