0
我正在試驗不同的方法來實現下面的輸出。自己加入一個表格以給出沒有null的記錄
CON_ID Compartment AMOUNT EXP_DT
train Compartment 1 100 '20-jan-2016'
請查找下面使用的數據。
with src_t as
(
select 'A' as miot_id,'Train' as Obj_id from dual
union
select 'B' as miot_id,'Candy' as obj_id from dual
),
eat as (
select 'Candy' as eat_id,'Compartment1' as compartment,'20-jan-2016' as exp_dt from dual
union
select 'Cookies' as eat_id,'Compartment2' as compartment,'20-feb-2016' as exp_dt from dual
),
miot_t as (
select 'A' as miot_id,'Compartment1' as vin from dual
UNION
select 'B' as miot_id,'Compartment2' as vin from dual
),
condition_t as (
select 'Train' as con_id,100 as amount from dual
)
我試過下面的查詢。
Select con_id,Compartment,amount
, exp_dt
From src_t
Left Join condition_t
On condition_t.con_id = src_t.obj_id
Left Join eat
On eat.eat_id = src_t.obj_id
Left Join miot_t
On miot_t.miot_id = src_t.miot_id;
但它顯示爲空值。
CON_ID Compartment AMOUNT EXP_DT
null Compartment 1 null '20-jan-2016'
Train null 100 null
我試過使用Max函數。這是做到這一點的一種方式,但是有沒有其他的方式呢..就像自我加入等等,所以它不會影響性能。感謝您的回答
這意味着車廂1列車有100個RS,關於'20 -JAN-2016'