如果任何源列为true,则将布尔值聚合为true [英] Aggregate boolean values to true if any of the source columns is true

查看:94
本文介绍了如果任何源列为true,则将布尔值聚合为true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有下表:

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

如果其中任何行

推荐答案

使用聚合函数 bool_or()

Use the aggregate function 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,则为true,否则为false

true if at least one input value is true, otherwise false

这篇关于如果任何源列为true,则将布尔值聚合为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆