通过使用第三个表连接两个表来创建表

发布于 2024-11-30 14:38:27 字数 709 浏览 0 评论 0原文

我有三个表:


表 1(770 万条记录)

ID_1|..|..|其他字段|


表 2(820 万条记录)

ID_2 |..|..|.....


表 12(750 万条记录)

ID_1| ID_2 |一些字段| AND ID_1== ID_2.ie 包含所有常见的 id

table 12 包含常见于 id 的唯一 id代码>表1和2。 我正在尝试创建一个新表,通过将 t12 中的记录与 id_1,id_2< 进行匹配来获取来自 t1t2 的所有数据/代码>)。

以下是我使用的sql:

CREATE TABLE ARROW_all_common12 AS 
SELECT T1.*, T2.* FROM T1, T2
LEFT JOIN T12 
ON T12.ID_1=T1.ID_1
LEFT JOIN T12
ON T12.ID_2 = T2.ID_2
WHERE T12.ID2 = T2.ID_2

I have three tables:


TABLE 1 (7.7million records)

ID_1|..|..| OTHER FIELDS|


TABLE 2 (8.2 million records)

ID_2 |..|..|.....


TABLE 12 (7.5 million records)

ID_1| ID_2 | SOMEFIELDS|
AND ID_1== ID_2.i.e. contains all common ids

The table 12 contains unique ids which are common to table 1 and 2.
I am trying create a new table to get all data from t1 and t2 by matching which records in t12 with id_1,id_2).

Following is the sql Iam using:

CREATE TABLE ARROW_all_common12 AS 
SELECT T1.*, T2.* FROM T1, T2
LEFT JOIN T12 
ON T12.ID_1=T1.ID_1
LEFT JOIN T12
ON T12.ID_2 = T2.ID_2
WHERE T12.ID2 = T2.ID_2

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

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

发布评论

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

评论(2

避讳 2024-12-07 14:38:27

我不完全确定你在这里问什么,但也许视图可能就是你正在寻找的?

CREATE VIEW someview AS (
    SELECT t1.*, t2.*
    FROM table12 AS t12
    INNER JOIN table1 AS t1
        ON t1.id_1 = t12.id1
    INNER JOIN table2 AS t2
        ON t12.id_2 = t2.id_2
)

I'm not entirely sure what you're asking here, but maybe a view could be what you're looking for?

CREATE VIEW someview AS (
    SELECT t1.*, t2.*
    FROM table12 AS t12
    INNER JOIN table1 AS t1
        ON t1.id_1 = t12.id1
    INNER JOIN table2 AS t2
        ON t12.id_2 = t2.id_2
)
清眉祭 2024-12-07 14:38:27

一样的,不太清楚。也许是这样?

create table t_all_12 as (
      select t1.*, t2.* 
      from t1, t2, t12
      where t12.id_1 = t1.id_1
      and t12.id_2 = t1.id_2
)

same, it's not quite clear. maybe that?

create table t_all_12 as (
      select t1.*, t2.* 
      from t1, t2, t12
      where t12.id_1 = t1.id_1
      and t12.id_2 = t1.id_2
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文