组合和连接两个具有不同编号的表。 列数和相同的列名

发布于 2024-07-10 15:24:19 字数 1531 浏览 9 评论 0原文

我尝试将fus_shift和根表合并到一个新表最终表中,但它的输出类似于“第2行错误: ORA-01789:查询块的结果列数不正确”。我也尝试加入表作为替代方案,但它也输出“第 3 行错误:ORA-00918:列定义不明确 ”。是否有另一种方法可以组合和连接两个具有不同列数且分别具有相同列名的表?再次感谢:-)

代码错误:
创建表最终为
从fus_shift中选择*
工会
select * from root;

代码错误:
选择记录号、测试号、t_date、t_time、system_type、类别、评论、val
来自fus_shiftrpt,根
其中 record_num=record_num;

我的表格:

                                 fus_shift Table


           Record_Num       test          date      time         system   
           -----------------------------------------------------------
                1          test15      08-11-12  13:20:01    sys23 
                2          test17      08-11-03  14:24:00    sys24
                3          test13      08-11-13  17:25:04    sys45
                4          test15      08-11-14  18:24:00    sys67
                5          test16      08-11-15  19:24:06    sys45


                                 root Table

           Record_Num      category   comments    validated by
           ---------------------------------------------------
                  1        dirt        checked        admin
                  2        prog        checked        admin
                  3        dirt        checked        pe
                  4        wires       checked        ee
                  5        prog        repair         admin

强调文本

I tried to combined tables which is fus_shift and root table into a new table which is final table but it outputs like "ERROR at line 2:
ORA-01789: query block has incorrect number of result columns
". I tried also joining table as my alternative but it also outputs "ERROR at line 3: ORA-00918: column ambiguously defined". Is there another way to do combining and joining two table with different number of columns and having the same column name respectively? Thanks again:-)

code error:
create table final as
select * from fus_shift
union
select * from root;

code error:
select record_num,test_num,t_date,t_time,system_type,category,comments,val
from fus_shiftrpt,root
where record_num=record_num;

my tables:

                                 fus_shift Table


           Record_Num       test          date      time         system   
           -----------------------------------------------------------
                1          test15      08-11-12  13:20:01    sys23 
                2          test17      08-11-03  14:24:00    sys24
                3          test13      08-11-13  17:25:04    sys45
                4          test15      08-11-14  18:24:00    sys67
                5          test16      08-11-15  19:24:06    sys45


                                 root Table

           Record_Num      category   comments    validated by
           ---------------------------------------------------
                  1        dirt        checked        admin
                  2        prog        checked        admin
                  3        dirt        checked        pe
                  4        wires       checked        ee
                  5        prog        repair         admin

emphasized text

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

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

发布评论

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

评论(2

诗化ㄋ丶相逢 2024-07-17 15:24:20

您当然不能将“Union”应用于您的表。 仅当两个查询返回相同数量(且类型相似)的列时才可以应用它。

您可以连接两个表,但在连接时必须使用“表别名”,因为“record_num”字段在两个表中都很常见。 这是适合您的查询

select 
        table1.record_num,
        table1.test_num,
        table1.t_date,
        table1.t_time,
        table1.system_type,
        table2.category,
        table2.comments,
        table2.val
from 
       fus_shift table1,root table2
where 
       table1.record_num = table2.record_num;

You certainly cannot apply "Union" to your tables. It can be applied only if both queries return same number (and of similar type) of columns.

You can join the two tables but would have to use "table alias" while joining since "record_num" field is common in both the tables. Here is the query that would work for you

select 
        table1.record_num,
        table1.test_num,
        table1.t_date,
        table1.t_time,
        table1.system_type,
        table2.category,
        table2.comments,
        table2.val
from 
       fus_shift table1,root table2
where 
       table1.record_num = table2.record_num;
铜锣湾横着走 2024-07-17 15:24:20

我会使用以下方法:

SELECT * 
FROM fus_shift
INNER JOIN root ON root.record_num = fus_shift.record_num

I would use the following method:

SELECT * 
FROM fus_shift
INNER JOIN root ON root.record_num = fus_shift.record_num
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文