【问题标题】:Google Cloud Spanner Pivot/Coalesce/wide table ability?Google Cloud Spanner Pivot/Coalesce/wide table 能力?
【发布时间】:2017-05-03 17:29:54
【问题描述】:

假设我有以下表格:

父母

| id    | name    |
-------------------
| 1     | Dave    |
| 2     | Alice   |

儿童

| id    | parent_id    | child_name  |
---------------------------------------
| 6     | 1            | Clint       |
| 7     | 1            | Oscar       |
| 8     | 2            | Oscar       |
| 9     | 1            | Davey       |

如果父母有很多孩子,是否可以像这样旋转父母表以引入所有孩子的名字:

| id    | name    | child_name | child_name | child_name |
----------------------------------------------------------
| 1     | Dave    | Clint      | Oscar      | Davey      |
| 2     | Alice   | Oscar      |            |            |

和/或查询所有有孩子叫“奥斯卡”或孩子叫“戴维”的父母?

在 Oracle/其他 SQL 引擎中,我们可以使用 PIVOT 或 COALESCE 函数,但在 Spanner 中这些都缺失并且无法查看这种类型的查询/输出是否可行?

【问题讨论】:

    标签: sql google-cloud-platform google-cloud-spanner


    【解决方案1】:

    PIVOT 看起来像 T-SQL 特定命令,它不在 SQL 2011 中。不过,Cloud Spanner 确实支持 COALESCE 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-07
      • 2017-09-02
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-10
      相关资源
      最近更新 更多