如何聚合布尔列 [英] How to aggregate boolean column

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

问题描述

我如何聚合这样的一些元组

How can I aggregate some tuples like this

COL_1 | COL_2 | COL_3 | COL_4
 val  |   T   |   F   |   F
 val  |   F   |   T   |   F

使用OR函数并返回下表?

with the OR function and return the following table?

COL_1 | COL_2 | COL_3 | COL_4
 val  |   T   |   T   |   F

推荐答案

只需执行GROUP BY,使用MAX()返回T(如果有),否则返回F.

Simply do a GROUP BY, use MAX() to return T if available, else F.

select col_1, max(col_2), max(col_3), max(col_4)
from tablename
group by col_1

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

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