Spark SQL:根据其他表中的列创建常量值
我有两个桌子: (1)线路
| ID | Client |
| --- | ------ |
| 0001| 0001 |
| 0001| 0002 |
| 0001| 0003 |
线将所有可用的客户端用于特定ID(可以有更多ID),并且是基表。运输是从line_update表(shipping_id field)取出的派生场。每当line_update表中提到客户端时,就必须从line_update col:shipping_id获取运输值。如果未在line_update中提到来自线表的客户端,则必须将属于客户端= 0000(line_update表)的shipptig_id值分配给行表中的运输字段。
- 因此,例如客户端:0001不在line_update表中,因此从line_update分配了客户端= 0000的运输值。
(2)LINE_UPDATE
| ID | Client | Shipping_ID |
| --- | ------|--------------|
| 0001| 0000 | 01234 |
| 0001| 0002 | 01222 |
LINE_UPDATE在行表中保留一些订单行,每当线路ID在LINE_UPDATE表中存在时,需要覆盖行值。
(3)预期表
| ID | Client | Shipping |
| --- | ------ | ---------|
| 0001| 0001 | 01234 |
| 0001| 0002 | 01222 |
| 0001| 0003 | 01234 |
我的问题。
有人知道我如何在line_update中创建一个新的列,该列将在新列中以新列中的consant值中的iD = 0000存储该值?
我的想法是使用cocece函数并执行逻辑,如果客户端位于LINE_UPDATE表中,则采用Shippting_id。如果不在line_update中,请在客户端= 0000的情况下以shippy_id值。
I have two tables:
(1) Line
| ID | Client |
| --- | ------ |
| 0001| 0001 |
| 0001| 0002 |
| 0001| 0003 |
Line holds all available clients for a specific ID (there can be more IDs) and is the base table. Shipping is a derived field taken from Line_Update table (Shipping_ID field). Whenever the Client is mentioned in the Line_Update table, then Shipping value must be taken from Line_Update col:Shipping_ID. If the Client from Line table is not mentioned in Line_Update then the Shipping_ID value that belongs to Client=0000 (Line_Update table) must be assigned to the Shipping field in Line table.
- So e.g. Client:0001 is not in the Line_Update table and therefore gets assigned the Shipping value for Client=0000 from Line_update.
(2) Line_update
| ID | Client | Shipping_ID |
| --- | ------|--------------|
| 0001| 0000 | 01234 |
| 0001| 0002 | 01222 |
Line_update holds some order lines from Line table that need to overwrite the Line value whenever the Line ID is there in the Line_Update table.
(3) Expected Table
| ID | Client | Shipping |
| --- | ------ | ---------|
| 0001| 0001 | 01234 |
| 0001| 0002 | 01222 |
| 0001| 0003 | 01234 |
My question.
Does anyone know how I can create a new column in Line_update that will store the value from Shipping where ID=0000 in Line table in a new column as constant value?
What my idea was, was to use coalesce function and perform the logic that if the client is in Line_Update table then take the Shipping_ID. If it is not in Line_Update take the Shipping_ID value where Client = 0000.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论