如果该值存在于其他列中,则排除该行

时间:2015-09-09 11:03:10

标签: mysql sql

有我的MYSQL表:

enter image description here

我想订购并测试num+1num的值是否存在,num+2num的值是否存在,或num+3中的值是否存在} {}存在于num中,num+4字段中的值存在于num中 - 对于所有行 - 如果为真,则删除该行。

预期结果:

enter image description here

我的代码是:

DELETE interface_T.num, interface_T.num+1, interface_T.num+2, interface_T.num+3, interface_T.num+4
FROM interface_T
WHERE (((interface_T.num+1) In (select num from interface_T ))) OR (((interface_T.num+2) In (select num from interface_T ))) OR (((interface_T.num+3) In (select num from interface_T ))) OR (((interface_T.num+4) In (select num from interface_T )));

3 个答案:

答案 0 :(得分:1)

这是你在找什么?

delete t
    from table t join
         table tnext
         on tnext.id in (t.num+1, t.num+2, t.num+3, t.num+4);

答案 1 :(得分:0)

<强>编辑:

如果在同一行的其他位置找到num值,则delete行。

delete from tablename
where num in (`num+1`, `num+2`,`num+3`, `num+4`)

答案 2 :(得分:0)

您能告诉我们您使用的查询吗?你使用了distinct子句吗? 首先尝试然后来评论

相关问题