当查询的主表中有引用到其他表中的ID字段,且有的内容为空的时候
select A.*, D.USER_FULLNAME AS APPLY_BY_NAME,
D.COMPANY_CODE AS APPLY_OFFICE,
C.user_fullname Submit_name,
B.APPROVE_DATE SUBMIT_DATE
from ifm_apply_bill A
from d_approve t1
where t1.approve_date =
(select max(approve_date)
from(d_approve)
where approve_state = '10'
and item_id = t1.item_id)) B on A.BILL_ID = B.item_id
left outer join D_user C on B.approve_by = C.user_code
left outer join D_USER D on A.APPLY_BY=D.USER_CODE
left outer join (select t1.approve_by, t1.item_id, t1.approve_date
此表为审核记录表,一条申请对应多条审核记录,取某一状态下的所有申请的最近一条