|id|___|char|
|12|___| A |
|57|___| B |
|12|___| C |
我想选择所有不同的id值!= A ...
我的查询给了我57和12,这是正确的...但是我不想要12 | C
,因为它还有另外一对与之相关的12 | A
....
如果ID为'12'的行与A有任何关系,我该如何选择不选择其他所有具有不同值的ID'12'的行?
答案 0 :(得分:0)
SELECT DISTINCT id FROM table WHERE id NOT IN (SELECT id FROM table WHERE char = 'A')
答案 1 :(得分:0)
SELECT DISTINT id
FROM table
WHERE id NOT IN (SELECT id FROM table WHERE char = 'A')
答案 2 :(得分:0)
尝试一下
SELECT DISTINCT ID,Char
FROM your_table
WHERE ID NOT IN
(
SELECT DISTINCT ID
FROM your_table
WHERE CHAR = 'A'
)
答案 3 :(得分:0)
SELECT DISTINT id,Char FROM table WHERE char != 'A'
答案 4 :(得分:0)
使用group by
:
select id
from t
group by id
having sum( char = 'A' ) = 0;