繁体   English   中英

根据 PostgreSQL 中 where 语句中的多个条件过滤行

[英]Filter rows based on multiple condition in where statement in PostgreSQL

我在 Postgres 11.0 中有下表

id              status
NCT00632827 true
NCT00632827 (null)
NCT00770185 false
NCT00770185 (null)
NCT00784303 (null)
NCT00784303 (null)

由于状态列中的值不同,id 值重复。 我想保留对或错的行。 如果多行有 null 值,我想只保留 1 行。 所需的 output 是:

id              status
NCT00632827 true
NCT00770185 false
NCT00784303 (null)

我正在尝试以下查询:

select id, status
where status = 'false' or status  = 'true'
from table

如何保留具有 null 值的行(所需输出中的最后一行)?

对于这个数据集,简单的聚合似乎足以产生预期的结果:

select id, bool_or(status) status from mytable group by id

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM