简体   繁体   English

MySQL查询与A列不同,所有查询在B列中都没有特定值

[英]MySQL query all distinct from column A where none of them has a specific value in column B

Could someone kindly point me to the right direction to seek further or give me any hints regarding the following task? 有人可以为我指出正确的方向以寻求进一步的建议,或者给我有关以下任务的任何提示吗?

I'd like to list all the distinct values from a MySQL table from column A that don't have a specific value in column B. I mean none of the same A values have this specific value in B in any of there rows. 我想列出来自A列的MySQL表中所有在B列中没有特定值的不同值。我的意思是,相同的A值在B中的任何行中都没有此特定值。 Taking the following table (let this specific value be 1): 取下表(将该特定值为1):

column A  | column B
----------------------
apple     |
apple     |
apple     | 1
banana    | anything
banana    |
lemon     |
lemon     | 1
orange    |

I'd like to get the following result: 我想得到以下结果:

banana
orange

Thanks. 谢谢。

Since there are null values, I have also added a nvl condition to column B . 由于存在空值,因此我还向列B添加了nvl条件。

ORACLE: ORACLE:

SELECT DISTINCT COLUMN_A  FROM MY_TABLE
WHERE COLUMN_A  NOT IN (SELECT COLUMN_A FROM MY_TABLE WHERE nvl(COLUMN_B,'dummy')  = '1');

MYSQL: MYSQL:

SELECT DISTINCT COLUMN_A  FROM MY_TABLE
WHERE COLUMN_A  NOT IN (SELECT COLUMN_A FROM MY_TABLE WHERE IFNULL(COLUMN_B,'dummy')  = '1');

This might help you: 这可能对您有帮助:

SELECT DISTINCT A FROM MY_TABLE
WHERE A NOT IN (SELECT DISTINCT A FROM MY_TABLE WHERE B = 1)
SELECT * FROM your_Table WHERE Column_A NOT IN(
    SELECT Column_A FROM Your_Table WHERE Column_B = '1'
)

This statement gives you the expected result: 该语句为您提供了预期的结果:

select COLUMNA from myTable where COLUMNA not in (select distinct COLUMNA from myTable where columnB
=1) group by COLUMNA;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL从列a中为每个不同的列b选择所有不同的值,其中计数不同的a> 1 - MySQL select all distinct values from column a for each distinct column b, where count distinct a >1 MySQL Select 将 A 列与 B 列存在的表不同,或者如果 B 列不存在,则基于 C 列的最新 - MySQL Select distinct column A from table where column B exists or if none with column B then latest based on column C 从表 B 更新表 A 中的列,其中值不存在于 MYSQL 中表 B 的不同结果中 - Update column in Table A from Table B where value does not exist in distinct result from Table B in MYSQL MySQL查询-选择具有特定值的不同值,按 - mysql query - select distinct value where it has a specific values , group by MySQL查询在列值上具有不同 - MySQL Query with distinct on a column value mySQL查询选择列,其中value = a或value = b等 - mySQL query select column where value = a or value = b etc MYSQL:获取列 A 中的不同值在列 B 中具有所有相同的值 - MYSQL: Obtaining distinct values in column A having all same value in column B MySQL查询速度慢(索引列上的DISTINCT WHERE) - MySQL query slow (DISTINCT WHERE on indexed column) MySQL查询组按何列区分 - mysql query group by where column distinct 如何在特定列Mysql中查询相同ID具有不同值的位置 - How to query where same id has different value in specific column Mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM