select a.托运单号,a.商场编号,a.客户简称,a.目的城市,a.条码单号,IsNull(d.预约内容,a.备注) as 预约内容 from (Select * from 托运单据
where 单据状态 = '开单入库' and 销单否 = '否' and 标记 = 0 and (预约状态 = '已预约' or 预约状态 = '不需要')) as a
left join (Select c.* from (Select max(ID) As id,托运单号 from 托运预约 group by 托运单号) b left join 托运预约 c on b.id = c.id and b.托运单号 = c.托运单号) As d on a.托运单号 =d.托运单号 ,条码单据 as p where a.条码单号 = p.条码单号 and p.状态 <> '初始'
具体你在看看,应该已经提升很多了