我正在研究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语句中的第二行,它设置了新表中的除法,我如何只从每个帐号中获取“Company:”Desc行?
最后,我希望我的决赛桌看起来像:
Account_Number | Company_Description
1 Company: ASDF123
2 Company: ASDF456
如果有任何不清楚或需要更多信息,请告诉我。
答案 0 :(得分: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
答案 1 :(得分: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;
希望有帮助.....