假设我有下表:
id column_a column_b column_c
1 t f t
2 t f f
3 f t f
根据上表,我想:
select rows from id = 1,2;
结果应该是:
column_a column_b column_c
t f t
如果定义的 id 中的任何行对于特定列为真,我们假定结果为真。
最佳答案
使用聚合函数bool_or()
.
SELECT bool_or(column_a) AS column_a
, bool_or(column_b) AS column_b
, bool_or(column_c) AS column_c
FROM tbl
WHERE id IN (1,2);
手册:
true if at least one input value is true, otherwise false
关于sql - 如果任何源列为真,则将 bool 值聚合为真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40415401/