我的表格包含以下列和数据条目(样本)
EID ROW_NUM ROW_VALUE
SM 1 E
SM 2 E
PM 2 E
SM 3 E
AM 3 S
PM 3 E
SM 4 E
AM 4 S
SM 5 S
AM 5 E
PM 5 E
SM 6 S
AM 6 E
PM 6 E
NM 6 S
我必须按row_num&组分组删除与以下组合匹配的记录(确切)
我正在研究如何制定一个可以删除或至少返回row_num的查询以进行此类组合?
如果需要,我可以添加更多信息
答案 0 :(得分:0)
我相信应该这样做:
select distinct row_num
from example_table t1
where
not (
exits ( select 1
from example_table t2
where t2.row_num=t1.row_num and t2.eid='SM' and t2.row_value='E')
and
exits ( select 1
from example_table t3
where t3.row_num=t1.row_num and t3.eid='PM' and t3.row_value='E')
)
and
not (
exits ( select 1
from example_table t4
where t4.row_num=t1.row_num and t4.eid='SM' and t4.row_value='S')
and
exits ( select 1
from example_table t5
where t5.row_num=t1.row_num and t5.eid='AM' and t5.row_value='E')
and
exits ( select 1
from example_table t6
where t6.row_num=t1.row_num and t6.eid='PM' and t6.row_value='E')
);