目录

PostgreSQL在where条件中使用判断条件

# PostgreSQL在where条件中使用判断条件

# 需求

我们平时查询数据是使用的mybatis,所以是这么写的

<select id="selectTable" resultType="java.util.Map">
    select * from Table
        <where>
            <if test="keyword!=null and keyword!=''">
                and keyword=#{keyword}
            </if>
        </where>

<select>
1
2
3
4
5
6
7
8
9

但是项目中有个使用动态sql直接查询的需求,在不能使用mybatis等解析查询语句的情况下该怎么实现呢?

# 使用case when

select * from Table where  (case when='' then 1=1 else Table.字段=end )
1

提示

这里的 == case when == 不是使用的 == case 字段 when ==
要使用 == case when 字段='' ==
上次更新: 2024-01-03, 13:22:13
最近更新
01
2023年度总结
01-03
02
MongoDB的简单的常用语法
12-11
03
cetnos7通过nfs共享磁盘文件
11-24
更多文章>