PostgreSQL 同时满足多组条件如何写查询语句

PostgreSQL 同时满足多组条件怎么写查询语句

现在有一个需求,同时满足多组条件(注:是多组)

表名为table,有type和code两个int字段,还有其他字段,现在要求可以查询出所有满足以下三组条件的数据:

type=1并且code=1(此为一组)

或type=2且code=3(此为一组)

或type=0且code=4(此为一组)

只要满足上述三组中任意一组即可,但是每组必须同时满足type和code的约束条件,请各位达人赐教!



不是这样么?

SQL code

select *
from table
where 
    (type=1 and code=1) or 
    (type=2 and code=3) or
    (type=0 and code=4)


探讨

不是这样么?
SQL code
select *
from table
where
(type=1 and code=1) or
(type=2 and code=3) or
(type=0 and code=4)


没有其它办法,这已经是最简单的方法了。
PostgreSQL 同时满足多组条件如何写查询语句

相关文章:

你感兴趣的文章:

标签云: