【问题标题】:delete sql rows that have same value in other rows删除其他行中具有相同值的sql行
【发布时间】:2015-10-26 23:34:22
【问题描述】:

我有一个数据表:

C1    || C2  
-----------------
a     || 1
b     || 1   
c     || 1   
a     || 0
b     || 0  
c     || 0   
d     || 0  

我必须删除第 4、5、6 行。 C2 = 0 的所有行,具有相同的 C1 和 C2 = 1。建议?

【问题讨论】:

  • 您应该自己尝试一下..从一些研究开始..它非常简单..如果您遇到查询问题,请返回

标签: sql-server-2008-r2 rows


【解决方案1】:
delete from your_table
where c2 = 0
and c1 in 
(
  select c1
  from your_table
  where c2 in (0,1)
  group by c1
  having count(distinct c2) = 2
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 2012-10-21
    • 2021-10-21
    • 2021-03-24
    • 2017-11-07
    • 2017-03-02
    • 2020-08-13
    相关资源
    最近更新 更多