簡體   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