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