select case when min(od_ship_date) = '1900/1/1' or min(od_ship_date) is null 
                            then min(tmp_ship_date)
                            else min(od_ship_date)
    end
 from (
select orderdtl_rec_id,od_ship_date = plan_ship_date,tmp_ship_date = null 
  from deli_not
 where ship_status <> 'I' 
       union 
select orderdtl_rec_id,od_ship_date = null,tmp_ship_date = plan_ship_date 
  from deli_not_temp
 where ship_status = '1'
) dn
group by dn.orderdtl_rec_id 
;請教怎麼樣優化以上SQL語句:如上:需求是,對於同一個orderdtl_rec_id編號的plan_ship_date,如果表deli_not中有資料,則取deli_not中的值,否則則取deli_not_temp中的值。orderdtl_rec_id 可能同時存在於兩個表,也可能隻存在於其中一個表。如果有多個orderdtl_rec_id ,則取最少值。謝謝!