0

我正在编写 Oracle 中的 SQL 脚本,该脚本从两个表中获取信息并创建一个新表。在我要从中检索数据的一个表中,有一个帐号列,然后对于每个帐号,都有 3 行附加到它上面。

Account # | Descriptor
1           Cost Center: ASDF
1           Company: ASDF123
1           Fund: JKL
2           Cost Center: ASDF12
2           Company: ASDF456
2           Fund: JKL23

这是我的脚本:

create table mydb.test as
select substr(db1.table1.Account_Num, 1, 6) as Account_Number,
       substr(db1.table1.Descriptor, 1, 2) as Company_Description,
  from db1.table1 
       join db1.table2 
           on db1.table1.Account_Num = db1.table2.Account_Num

我的问题是,对于 select 语句中的第二行,它在新表中设置了部门,我怎样才能从每个帐号中只获取“公司:” Desc 行?

最后,我希望我的决赛桌看起来像:

Account_Number | Company_Description
1                Company: ASDF123
2                Company: ASDF456

如果有任何不清楚或需要更多信息,请告诉我。

4

2 回答 2

1

怎么样:

create table mydb.test as
select substr(db1.table1.Account_Num, 1, 6) as Account_Number,
       substr(db1.table1.Descriptor, 1, 2) as Company_Description,
  from db1.table1 
       join db1.table2 
           on db1.table1.Account_Num = db1.table2.Account_Num
 where db1.table1.descriptor like 'Company:%'
        order by Account_Number Desc;

希望有帮助......

于 2013-10-28T18:00:39.820 回答
1

以下陈述对我来说很好:

create table mydb.test as
select substr(db1.table1.Account_Num, 1, 6) as Account_Number,
       substr(db1.table1.Descriptor, 1, 2) as Company_Description,
  from db1.table1 
       join db1.table2 
           on db1.table1.Account_Num = db1.table2.Account_Num
        order by Account_Number Desc 
于 2013-10-28T14:58:09.337 回答