28.组合JOIN

JOIN, NEST和UNNEST运算可以链接和组合一起使用.

在下边的例子,我们执行一个UNNEST运算生成一个完整的订单包含订单id和用户详细信息。这是与users_with_orders桶的订单。

Query:

SELECT  u.personal_details.display_name name, s AS order_no, o.product_details  
    FROM users_with_orders u USE KEYS "Aide_48687583" 
        UNNEST u.shipped_order_history s 
            JOIN users_with_orders o ON KEYS s.order_id

结果:

{
  "results": [
    {
      "name": "Aide Swank",
      "order_no": {
        "order_datetime": "Sat Jan  7 22:00:11 2012",
        "order_id": "T638751835595"
      },
      "product_details": {
        "currency": "USD",
        "list_price": 178,
        "pct_discount": 25,
        "product_id": "P8360066417",
        "sale_price": 134
      }
    },
    {
      "name": "Aide Swank",
      "order_no": {
        "order_datetime": "Fri Jan 20 22:00:11 2012",
        "order_id": "T870351974549"
      },
      "product_details": {
        "currency": "USD",
        "list_price": 179,
        "pct_discount": 5,
        "product_id": "P8589655279",
        "sale_price": 171
      }
    },
    {
      "name": "Aide Swank",
      "order_no": {
        "order_datetime": "Sun Feb 19 22:00:11 2012",
        "order_id": "T769348087819"
      },
      "product_details": {
        "currency": "EUR",
        "list_price": 608,
        "pct_discount": 10,
        "product_id": "P1512413007",
        "sale_price": 548
      }
    },
    {
      "name": "Aide Swank",
      "order_no": {
        "order_datetime": "Mon Oct 15 22:00:11 2012",
        "order_id": "T183428307793"
      },
      "product_details": {
        "currency": "USD",
        "list_price": 683,
        "pct_discount": 5,
        "product_id": "P3705096321",
        "sale_price": 649
      }
    },
    {
      "name": "Aide Swank",
      "order_no": {
        "order_datetime": "Sun Aug  5 22:00:11 2012",
        "order_id": "T703068425987"
      },
      "product_details": {
        "currency": "EUR",
        "list_price": 62,
        "pct_discount": 10,
        "product_id": "P7771903542",
        "sale_price": 56
      }
    }
  ]
}

Last updated

Was this helpful?