试图通过两个不同桌子的时间戳订购行雪花
我有两个表,如下所示,
table_1
person_id | ldts |
---|---|
45 | 2022-03-03 15:41:05.685 |
72 | 2022-03-03-03 15:42:42:08.203 |
15 | 2022-06-06-06-08 21:57:57:57:07.909 36 2022-06-28 21:07.909 |
36 | 2022-06-28 21:07.909 58:43.558 |
Table_2
Person_Id | LDTS | 货币 |
---|---|---|
34 | 2022-03-03 15:00:21.814 | 28 |
2022-03-03 | 15:02:02:05.963 | 52 |
2022-03-03-03 | 15:02:05:05.963 | US |
10 | 2022-06-06-08 14:40:40:13.762 | US |
US | CA 06-08 14:40:13.762 | CA |
19 | 2022-06-14 16:10:19.005 | 我们 |
试图通过时间戳加入这些表和订单,以便获得诸如
Person_ID | Table_1.ldts | Table_2.ldts | Currency之 |
---|---|---|---|
类的结果34 | NULL | 2022-03-03-03 15:00:21.814 | US |
28 US 28 | NAULL 2022 --NULL | 2022- 03-03 15:02:05.963 | CA |
52 | NULL | 2022-03-03 15:02:05.963 | US |
45 | 2022-03-03 15:41:05.685 | NULL NULL | NULL NULL |
72 | 2022-03-03 15:42:08.203 | NAULL | NULL NULL |
10 | NULL | 2022-06-08 14:40:13.762 | US |
11 | NULL | NULL 10 NULL 10 :13.762 | CA |
15 | 2022-06-08 21:57: | 07.909 | NULL |
19 | NULL | 2022-06-14 16:10:19.005 | US |
36 | 2022-06-28 21:58:43.558 | NINULL | NULL NULL |
是否只是在LDTS上加入吗?我不确定如何获取结果表以使时间戳以这种方式排序,如果其值不在另一个表中,则不共享的列包含nulls。当我尝试进行完整的外部连接时,看起来行复制了LDTS,而LDTS成为一个单数列,而其他列的值都是无效的。谢谢!
I have two tables as follows
TABLE_1
PERSON_ID | LDTS |
---|---|
45 | 2022-03-03 15:41:05.685 |
72 | 2022-03-03 15:42:08.203 |
15 | 2022-06-08 21:57:07.909 |
36 | 2022-06-28 21:58:43.558 |
TABLE_2
PERSON_ID | LDTS | CURRENCY |
---|---|---|
34 | 2022-03-03 15:00:21.814 | US |
28 | 2022-03-03 15:02:05.963 | CA |
52 | 2022-03-03 15:02:05.963 | US |
10 | 2022-06-08 14:40:13.762 | US |
11 | 2022-06-08 14:40:13.762 | CA |
19 | 2022-06-14 16:10:19.005 | US |
I am trying to join these tables and order by timestamp in order to get a result such as
PERSON_ID | TABLE_1.LDTS | TABLE_2.LDTS | CURRENCY |
---|---|---|---|
34 | NULL | 2022-03-03 15:00:21.814 | US |
28 | NULL | 2022-03-03 15:02:05.963 | CA |
52 | NULL | 2022-03-03 15:02:05.963 | US |
45 | 2022-03-03 15:41:05.685 | NULL | NULL |
72 | 2022-03-03 15:42:08.203 | NULL | NULL |
10 | NULL | 2022-06-08 14:40:13.762 | US |
11 | NULL | 2022-06-08 14:40:13.762 | CA |
15 | 2022-06-08 21:57:07.909 | NULL | NULL |
19 | NULL | 2022-06-14 16:10:19.005 | US |
36 | 2022-06-28 21:58:43.558 | NULL | NULL |
Would this just be a left join on LDTS? I am not sure how to get the resulting table such that the timestamps are ordered in this way and the columns that are not shared contain nulls if their values are not in the other table. When I try to do a full outer join, it looks like rows are duplicated for LDTS and LDTS becomes a singular column while the values for the other columns are all null. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
获取另一个表中的键的行可以作为基于设定的问题来处理:
响应评论中的问题,如果Table_2没有Person_ID列,则只需指定它的null:null:
Getting the rows where the key in the other table is null reciprocally could be handled as a set-based issue:
In response to the question in the comments, if TABLE_2 does not have a PERSON_ID column, then simply specify that it's null:
Another one - similar to @Greg -
Another one - similar to @Greg -
是否想做这样的事情,也可以做到这一点
还是如果您真的想要以发布格式,您
Or were you trying to do something like this
IF you really wanted in the format you posted, you can also do this