karon pa gyod ko katarong og simulate.
Code:
select x.id,
x.freightbill,
decode(y.timestamp,NULL,'NULL',to_char(y.timestamp,'HH:MI AM')) timestamp,
decode(y.status,NULL,'NULL',y.status) status
from freight_bill x
left outer join (
select b.id id,
b.freightbill freightbill,
b.timestamp timestamp,
b.status status
from history b
where b.timestamp=(Select max(a.timestamp)
from history a
where a.freightbill=b.freightbill)) y
on x.freightbill=y.freightbill
tested on oracle db with the ff output
Code:
ID FREIGHTBILL TIMESTAM STATUS
---------- ------------------------------ -------- ------------------
1 frght0001 07:00 PM analysis
2 frght0002 05:00 PM requeue
3 frght0003 05:00 PM NULL
4 frght0004 08:30 PM requeue
5 frght0005 NULL NULL
6 frght0006 NULL NULL
6 rows selected.
mas limpyo kong hinoon kong i view ni cya nga subquery
Code:
create or replace view history_vw
as
select b.id id,
b.freightbill freightbill,
b.timestamp timestamp,
b.status status
from history b
where b.timestamp=(Select max(a.timestamp)
from history a
where a.freightbill=b.freightbill)
and instead of putting the subquery for the outer join,
use the view
Code:
select x.id,
x.freightbill,
decode(y.timestamp,NULL,'NULL',to_char(y.timestamp,'HH:MI AM')) timestamp,
decode(y.status,NULL,'NULL',y.status) status
from freight_bill x
left outer join history_vw y
on x.freightbill=y.freightbill
mas refine cya, then dali sabton