17,086
社区成员
发帖
与我相关
我的任务
分享
select * from t
where (
(t.code='A' or t.code='B')
and 'A'='A' )
or (t.code<>'A'
and t.code<>'B'
and 'A'='B')
至少这种写法在java程序员中还算常见。逻辑与或的活用经常用来替代持久层中不美观的标签,但是你上面这种处理更像是在用sql处理一些应用逻辑。举例来说,你上面语句的源码很可能是这样的
select * from t
where (
(t.code='A' or t.code='B')
and 'A'=#{state} )
or (t.code<>'A'
and t.code<>'B'
and 'B'=#{state})
state是前台传来的状态码。当状态为A时,筛选code为AB的,为B时,筛选code不为AB的