本文介绍了RethinkDB - 左联接,joined_table.identifier 为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 RethinkDB 数据库中有两个表,它们表示一对多关系.考虑以下两个表:
I have two tables in a RethinkDB database that represent a one-to-many relationship. Consider the following two tables:
t1
ParentId Name
1 lorem
2 ipsum
3 dotor
4 sit
5 amet
t2
ChildId ParentId ChildName
1 1 something
2 3 random
3 5 here
在 t1 上,ParentId 是主键,在 t2 上,ParentId 上有一个二级索引.我想找出哪些父母没有孩子.SQL(确切地说是 MSSQL)中的操作如下所示:
On t1, ParentId is the primary key, and on t2, there is a secondary index on ParentId. I want to find which parents don't have a child. The operation in SQL (MSSQL to be exact) looks like this:
SELECT t1.*
FROM t1
LEFT OUTER JOIN t2 ON t2.ParentId = t1.ParentId
WHERE t2.ChildId IS NULL
Results:
ParentId Name
2 ipsum
4 sit
如何在 RethinkDB 中实现类似的结果?谢谢!
How can I accomplish this similar result in RethinkDB? Thank you!
推荐答案
我会这样做:
r.table('t1').filter(function(parent) {
return r.table('t2').get_all(parent('ParentId'), {index: 'ParentId'}).count().eq(0);
})
这篇关于RethinkDB - 左联接,joined_table.identifier 为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!