在同一表中扩展列值

发布于 2025-01-19 01:45:18 字数 663 浏览 3 评论 0原文

我有以下数据表,其中wid和parentID是同一列的值,但彼此相关。此处显示的状态是针对WID的,我想将另一列作为parentidState扩展为parentidstate,该列应该是parentid的状态。 (状态的价值也存在于同一表中)。我该怎么办?

datatable(WId:int, WType:string, Link:string, ParentId:dynamic, State:string)
[
    374075, "Deliverable", "Link", dynamic(315968), "Started", 
]

进一步更新以进行澄清 -

datatable(WId:int, WType:string, Link:string, ParentId:dynamic, State:string)
[
    374075, "Deliverable", "Link", dynamic(315968), "Started", 
    315968, "Parent", "Link", dynamic(467145), "Planned"
]

parentid是动态的,因为它是从JSON中提取的。在上面的数据表中,parentID实际上是WID的值,并且具有相关的详细信息。我的目的是扩展我的表格,以在下面的另一列中给出父态

I have the below datatable, where WId and ParentId are values of the same column but are related to each other. The State that's shown here is for WId, I want to extend another column as ParentIdState which should be the State of ParentId. (The value of State also exists in the same table). How can I do so?

datatable(WId:int, WType:string, Link:string, ParentId:dynamic, State:string)
[
    374075, "Deliverable", "Link", dynamic(315968), "Started", 
]

Updating further for clarification -

datatable(WId:int, WType:string, Link:string, ParentId:dynamic, State:string)
[
    374075, "Deliverable", "Link", dynamic(315968), "Started", 
    315968, "Parent", "Link", dynamic(467145), "Planned"
]

ParentId is dynamic because it's extracted from a JSON. In the above datatable ParentId is actually a value of WId and has its relevant details. My intent is to extend my table to give ParentState in another column like below -

Table

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李不 2025-01-26 01:45:18

您应该使用 /a>或

You should use join or lookup.

帅冕 2025-01-26 01:45:18

我相信您可以 join 2 个表:

  1. 您提供的表进行了小修改 - ParentId 的类型从 dynamic 更改为 int (与 WId 的类型相同,因为将对其执行连接)。
  2. 表 1) 的简化版本 - 仅包含 2 列:WIdState
let data = datatable(WId:int, WType:string, Link:string, ParentId:dynamic, State:string)
[
    374075, "Deliverable", "Link", dynamic(315968), "Started", 
    315968, "Parent", "Link", dynamic(467145), "Planned"
]
| extend ParentId = toint(ParentId); // to make sure the type of ParentId is the same as WId

data
| join kind=leftouter (data | project WId, State) on $left.ParentId == $right.WId
| project WId, WType, Link, ParentId, State, ParentState = State1

这里可能需要进行一些优化(例如通过使用 materialize,但我不完全确定)

你也可以实现与查找

data
| lookup (data | project WId, State) on $left.ParentId == $right.WId
| project WId, WType, Link, ParentId, State, ParentState = State1

I believe you could join 2 tables:

  1. the one you provided with a small modification - type of ParentId is changed from dynamic to int (the same as the type of WId as the join will be performed on it).
  2. a simplified version of table 1) - with only 2 columns: WId and State
let data = datatable(WId:int, WType:string, Link:string, ParentId:dynamic, State:string)
[
    374075, "Deliverable", "Link", dynamic(315968), "Started", 
    315968, "Parent", "Link", dynamic(467145), "Planned"
]
| extend ParentId = toint(ParentId); // to make sure the type of ParentId is the same as WId

data
| join kind=leftouter (data | project WId, State) on $left.ParentId == $right.WId
| project WId, WType, Link, ParentId, State, ParentState = State1

There might be some optimization to be done here (for example by using materialize, but I'm not entirely sure)

You can also achieve the same with lookup

data
| lookup (data | project WId, State) on $left.ParentId == $right.WId
| project WId, WType, Link, ParentId, State, ParentState = State1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文