当某个字段值不为空值时则新增一个and条件

1.一般是加一个<if>标签,但是只能是参数,如果是想查出来的某个字段不为空的话,不太好用,

今天看到一个巧妙的写法

select t1.name,t1.work,t2.type from t1,t2 where t.name=t2.name and (t2.date is null or t1.postdate < t2.date)

(t2.date is null or t1.postdate < t2.date)。 and (是空or+条件)

这样性能也许会有影响,但管不了这么多了,因为逻辑太复杂了。

posted @ 2024-08-14 15:05  了悟  阅读(2)  评论(0编辑  收藏  举报