select case when A.a = 2 then C.xxx else B.xxx endfrom A inner join B on A.xxx = B.xxinner join C on A.xxx = C.xxx