select A.ID
,isnull(T.dt,A.inserttime) as 'updatetime'
from A
left join (
select ID,
max(updatetime) as 'dt'
from B
group by ID
)T on A.ID=T.ID
,isnull(T.dt,A.inserttime) as 'updatetime'
from A
left join (
select ID,
max(updatetime) as 'dt'
from B
group by ID
)T on A.ID=T.ID
不知道有isnull这个函数