我試圖刪除列B ='S'的列A值的所有行。下面是一個例子,我可以用數據顯示:根據列值排除查詢結果中的行
column A column B
100 S
100 P
100 C
101 P
101 C
102 S
103 C
104 P
從這裏,我想消除從塔A,顯示「S」在列B(100和102)中的所有條目,所以我留給:
column A column B
101 P
101 C
103 C
104 P
我試圖遵循從類似SO柱(Exclude rows with a column containing a value if multiple rows exist for)中的步驟,但它不包括保持其中「S」的存在,以及保持共享的列的A值的行。
例如,這裏是我的查詢相關部分我工作:
select table_a.column_a
,table_b.column_b
,...
from table_z
inner join table_b
on table_z.z = table_b.z
inner join table_y
on table_z.y = table_y.y
left outer join table_a
on table_x.x = table_a.x
where date > 'YYYY-MM-DD'
and (
table_b.column_b not in (
select column_b
from table_b
where (column_b = 'S')
)
)
order by table_a.column_a
但它只是刪除了行,其中column_b =「S」,並且不與column_A值匹配刪除的行其中column_b出現(column_a = 100本示例開始處的示例)。