【问题标题】:Child grandparent relationship either in SQL or Qlik SenseSQL 或 Qlik Sense 中的子祖父母关系
【发布时间】:2017-05-22 17:38:36
【问题描述】:

我只有一张桌子

从上表中我需要找出 child_ID 的祖父母。

输出必须如下所示

请让我知道 SQL 或 Qlik Sense 中的代码。

提前致谢。

【问题讨论】:

  • 你能分享一下你到目前为止的尝试吗?
  • 我不清楚 child_id d 有 a 的祖父母吗?我想这应该只适用于 child_id c。还是我错过了什么?
  • child_id b的parent_id和grandparent_id怎么是'a'?怎么可能是一样的?
  • 预期输出不是祖父母ID,而是列出每个孩子的最终父母(根)。另外,您的帖子中没有问题,只有代码请求。
  • @India.Rocket 这不是问题。这是一个需求声明。

标签: mysql sql qlikview qliksense


【解决方案1】:

从你的例子很难判断你真正想要做什么,但我假设你正在尝试创建一个层次结构。

在 Qlik 中,您要查找的内容称为 Hierarchy

对于您的示例,请参见以下脚本:

Data:
LOAD * INLINE [
    Parent_ID, Child_ID
    a, b
    b, c
    c, d
    d, e
];

Hierarchy (Child_ID, Parent_ID, Title, 'Parent')
LOAD 
Parent_ID,
Child_ID,
Parent_ID as Title
Resident Data;

由于您没有标题,因此我使用 Parent_ID 作为标题。

【讨论】:

    猜你喜欢
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    相关资源
    最近更新 更多