[英]Fetching a distinct column only if duplicates columns have the same data
I have this type of table:我有这种类型的表:
+-----TABLE1----+
| Name, Boolean |
| A , 0 |
| B , 0 |
| B , 0 |
| A , 1 |
| C , 1 |
| D , 0 |
| C , 0 |
| A , 0 |
| A , 1 |
| B , 0 |
| D , 0 |
+--------------+
I want to select distinct all names that their duplicates booleans are 0 aswell.我想 select 区分所有重复布尔值也为 0 的名称。 So the result will be:
所以结果将是:
+---------------+
| RESULT: |
| Name |
| B |
| D |
+---------------+
Because A and C contains boolean also of "1" so they wont be fetched因为 A 和 C 包含 boolean 也是“1”,所以它们不会被提取
I can do:我可以:
SELECT DISTINCT name, MAX(boolean) as boolean FROM table1 GROUP BY name;
But what condition I need to use if I want to fetch only the results that their max(boolean) are 0?但是,如果我只想获取它们的 max(boolean) 为 0 的结果,我需要使用什么条件?
I can't use two select statements inside one query because we are talking about big data database.. so this solution is not an option in my case:我不能在一个查询中使用两个 select 语句,因为我们正在谈论大数据数据库。所以在我的情况下,这个解决方案不是一个选项:
SELECT DISTINCT t1.name FROM table1 t WHERE t1.name NOT IN (SELECT DISTINCT t2.name FROM table1 t2 WHERE t2.boolean = 1);
Couldn't think of an option when using "JOIN" aswell.在使用“JOIN”时也想不出一个选项。
Any solutions?有什么解决办法吗?
Thanks in advance: :)提前致谢: :)
You can use aggregation:您可以使用聚合:
select name
from table1 t
group by name
having min(boolean) = max(boolean);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.