select * from bw bw left outer join az az on az.az_aa = case when bw_aa > 0 then null else 0 end and az.az_anr = bw.bw_ak and az.az_pos = bw.bw_az