2017-07-28 39 views
0

如何與多個條件加入,並在反思-DB使用聚合函數加盟RethinkDB

r.table("yourtable").get(id).innerJoin(
r.table("secondtable"),function (up, upp) { 
     return user_profile("mID") 
}).map({ 
    uId: r.row("left")("userId"), 
    mId: r.row("left")("memberId"), 
    pId: r.row("right")("projectId"),  
    nodeId: r.row("right")("nodeId"), 
    pri: r.row("right")("priority") 
}) 
.min("priority"); 
+0

任何錯誤味精? – Cedias

回答

1

你可以試試下面一個地方tblName1與tblName2加入。將userId作爲映射關鍵字。注意它是一個innerJoin。

r.table("tblName1").get(id).innerJoin(
    r.table("tblName2"), 
    function (tbl1, tbl2) { 
    return tbl1("userId").eq(tbl2("userid")); 
    }).zip() 

此外,您可以檢查所有sql的引用reql here。 希望它能幫助:)

3
r.table("tblName1").get(id).innerJoin(
    r.table("tblName2"), 
      function (tbl1, tbl2) { 
       return tbl1("userId").eq(tbl2("userid")); 
    }) 
1
.table("tblName1").innerJoin(
    r.table("tblName2"), function(tl, path){ 
    return tblName1("value").eq(path("value")); 
    } 
).map({nodeName:r.row("right")("value") 
    })