(select A from 'TableB' where C = c and G = g)
intersect
(select A from 'TableB' where C = d and G = h)
首先,因为Mysql不提供相交运算符,所以我如下更改了上面编写的查询语句。
select A
from 'TableB'
where C = c and G = g and A in(
select A
from 'TableB'
where C = d and G = h)
我想使用MongoDB获得与上述相同的结果。
还有其他方法吗?
let mongoQuery = {
$and:[
{C: c},
{D: d},
{G: g},
{G: h}
]
};
const result = await TableB.find(mongoQuery, {A: 1});
此查询将仅返回'A'中与C=c
和D=d
相匹配的元素
希望有帮助