【发布时间】:2018-01-31 19:46:56
【问题描述】:
当表格同时包含空白/空行和多行时,我试图返回 1 行。
Table1.cust(唯一) Table2.prop(3个字段创建一个具有一对多自定义的唯一ID) Table3.start(唯一的 [cust, prop and start] 一些空白/空记录存在于 cust)
问题在于解码和 table1、table2 和 table 3 连接。如果我只是与 table1 进行连接而不进行解码,我会得到额外的记录并且没有得到空记录,但是当我合并三个表时,我仍然没有得到空白/空记录。
示例代码
select table1.cust,
table2.prop.(3 fields),
decode(table3.startdate,' ','1901/01/01',
null,'1901/01/01',
table3.start)
from table1, table2(subquery), table3(subquery)
where table1 = table2(+)
and (table1.cust = table2.cust(+)
and table2.(3 fields) = table3.(3 fields))
返回 客户 1、道具 3、日期 3 Cust2 - 失踪 客户 3、道具 2、日期 2 Cust4, prop1, date1
示例代码
select table1.cust,
table2.prop.(3 fields),
decode(table3.startdate,' ','1901/01/01',
null,'1901/01/01',
table3.start)
from table1, table2(subquery), table3(subquery)
where table1 = table2(+)
and (table1.cust = table2.cust(+)
and table2.(3 fields) = table3.(3 fields))
返回
Cust1, prop1, date1 (not the last record)
Cust1, prop2, date2 (not the last record)
Cust1, prop3, date3 - Good
Cust2, prop1, date1 - Good
Cust3, prop1, date1 (not the last record)
Cust3, prop2, date2 - Good
Cust4, prop1, date1 - Good
【问题讨论】: