【问题标题】:How do I remove rows based off of cell value? - SQL如何根据单元格值删除行? - SQL
【发布时间】:2020-10-16 21:31:49
【问题描述】:

如果可能的话,试着看看是否有人可以提供帮助。

我正在尝试找到一种方法,让 SQL 识别列为铝的任何内容,然后删除与该品牌关联的所有行。因此,在 Coors 有铝的地方,它消除了所有 Coors 行。

示例:

Brand       Alcohol  Container
Absolute     Vodka    Glass
Absolute     Vodka    Plastic
Coors        Beer     Glass
Coors        Beer     Aluminum
Coors        Beer     Plastic
Gallo        Wine     Glass
Yellowtail   Wine     Glass
Yellowtail   Wine     Aluminum
Yellowtail   Wine     Plastic
Corona       Beer     Plastic
Corona       Beer     Glass

成品:

Brand       Alcohol  Container
Absolute     Vodka    Glass
Absolute     Vodka    Plastic
Gallo        Wine     Glass
Corona       Beer     Plastic
Corona       Beer     Glass

谢谢, 马特

【问题讨论】:

    标签: sql subquery where-clause


    【解决方案1】:

    你可以使用not exists:

    select t.*
    from mytable t
    where not exists (
        select 1 
        from mytable t1 
        where t1.brand = t.brand and t1.container = 'Aluminium'
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 1970-01-01
      • 2018-11-11
      相关资源
      最近更新 更多