原始语句大致如上,现在我想在语句做一个判断,如果a1 is null,那么where后面就是a.a1=b.b1;如果a1 is not null,那么where后面就是a2 = b1。
求大神语句如何修改!!!
------解决方案-------------------- select a1,a2 from a,b where (a1 is null and a.a1=b.b1) or (a1 is not null and a.a2=b.b1) ------解决方案-------------------- select a1,a2 from a,b where case when (a.a1 is null then a.a1 else a.a2 end)=b.b1 ------解决方案--------------------