简体   繁体   English

仅当重复列具有相同数据时才获取不同的列

[英]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.

相关问题 如何仅返回一列中的不同结果,同时允许其他列中的重复结果? - How to return only distinct results within one column, while allowing duplicates in other columns? 查找相同列数据的重复项 - Finding duplicates of the same column data 如何选择不同的行,其中一列可能具有许多相同的值,但所有第二列均具有相同的值? - How do I select distinct rows where a column may have a number of the same values but all their 2nd columns have the same value? 如何使用SQL / mySQL选择2列具有相同值的多个且1列具有不同值的行? - How do I use SQL/mySQL to select rows where 2 columns have multiple of the same value and 1 column has a distinct value? SQL查询以查找第一列中的值相同的两列中的重复项 - Sql Query to find duplicates in 2 columns where the values in first column are same 相同列的 MySql 不同 - MySql Distinct for same columns 删除所有重复的查询结果(不区分) - Remove all query results that have duplicates (NOT DISTINCT) MySQL-从一列中随机选择4个数据,以2个不同的列区分 - Mysql - select random 4 data from a column, distinct by 2 different columns 按同一列计算不同 - Count distinct by same column 即使SELECT数据来自同一源表和列,MySql表列也具有不同的CHARSET和COLLATION? - MySql table columns have different CHARSET and COLLATION even when SELECT data is from the same source table and column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM