16.快速回顾

我们继续进一步探索N1QL之前,让我们看看一个查询,总结了到目前为止我们学到了什么。

我们匹配的people结果条件:

有一个雅虎的电子邮件地址或其中有一个在10岁以上的孩子,并且满足搜索的字段中有一个匹配到'dave', 'ian'关键中的其中一个。

当匹配到这个人,满足这些需求,我们展示他们的姓名,电子邮件地址,和的children完整列表。

Query:

SELECT fname || " " || lname AS full_name, email, children[0:2] AS offspring
    FROM tutorial USE KEYS ['dave', 'ian']
        WHERE email LIKE '%@yahoo.com' 
        OR ANY child IN tutorial.children SATISFIES child.age > 10 END

结果:

{
  "results": [
    {
      "email": "dave@gmail.com",
      "full_name": "Dave Smith",
      "offspring": [
        {
          "age": 17,
          "fname": "Aiden",
          "gender": "m"
        },
        {
          "age": 2,
          "fname": "Bill",
          "gender": "f"
        }
      ]
    },
    {
      "email": "ian@gmail.com",
      "full_name": "Ian Taylor",
      "offspring": [
        {
          "age": 17,
          "fname": "Abama",
          "gender": "m"
        },
        {
          "age": 21,
          "fname": "Bebama",
          "gender": "m"
        }
      ]
    }
  ]
}

Last updated

Was this helpful?