13.AND,OR 组合多个条件
AND - 并的关系
OR - 或的关系
匹配文档满足两个或两个以上的条件。
在下边的例子,我们只返回people 至少有一个孩子并且有一个gmail地址。
AND Query:
SELECT fname, email, children
FROM tutorial
WHERE ARRAY_LENGTH(children) > 0 AND email LIKE '%@gmail.com'
结果:
{
"results": [
{
"children": [
{
"age": 17,
"fname": "Aiden",
"gender": "m"
},
{
"age": 2,
"fname": "Bill",
"gender": "f"
}
],
"email": "dave@gmail.com",
"fname": "Dave"
},
{
"children": [
{
"age": 17,
"fname": "Xena",
"gender": "f"
},
{
"age": 2,
"fname": "Yuri",
"gender": "m"
}
],
"email": "earl@gmail.com",
"fname": "Earl"
},
{
"children": [
{
"age": 17,
"fname": "Abama",
"gender": "m"
},
{
"age": 21,
"fname": "Bebama",
"gender": "m"
}
],
"email": "ian@gmail.com",
"fname": "Ian"
}
]
}
在下边的例子,我们只返回 至少有一个孩子的people或有一个gmail地址的people。
OR Query:
SELECT fname, email, children
FROM tutorial
WHERE ARRAY_LENGTH(children) > 0 OR email LIKE '%@gmail.com'
结果:
{
"results": [
{
"children": [
{
"age": 17,
"fname": "Aiden",
"gender": "m"
},
{
"age": 2,
"fname": "Bill",
"gender": "f"
}
],
"email": "dave@gmail.com",
"fname": "Dave"
},
{
"children": [
{
"age": 17,
"fname": "Xena",
"gender": "f"
},
{
"age": 2,
"fname": "Yuri",
"gender": "m"
}
],
"email": "earl@gmail.com",
"fname": "Earl"
},
{
"children": null,
"email": "fred@gmail.com",
"fname": "Fred"
},
{
"children": [
{
"age": 17,
"fname": "Abama",
"gender": "m"
},
{
"age": 21,
"fname": "Bebama",
"gender": "m"
}
],
"email": "ian@gmail.com",
"fname": "Ian"
},
{
"email": "jane@gmail.com",
"fname": "Jane"
}
]
}
Last updated
Was this helpful?