HI 有 3 个产品表,每个表有 3 列,即客户名称、布尔选择退出和黑名单。在 Have 子句之后,每个客户名称将有 3 行(假设他拥有所有 3 个产品)。
如果任何布尔列包含真值,我如何输出真值。我通过使用下面的 cast 操作想通了,但认为应该有一个更优雅的解决方案。
SELECT customer_name,
cast(int4(sum(cast(optout As int4))) As Boolean) As optout,
cast(int4(sum(cast(blacklist As int4))) As Boolean) As blacklist
FROM
(SELECT * FROM product1
UNION SELECT * FROM product2
UNION SELECT * FROM product3) AS temp1
GROUP BY customer_name, optout, blacklist
HAVING optout=true or blacklist=true;