gpt4 book ai didi

sql - 基于两列删除重复项

转载 作者:行者123 更新时间:2023-12-05 04:12:31 25 4
gpt4 key购买 nike

我有这张表,我想要一个 SELECT 来排除标记的行。一般规则是:

  • 如果有两行或更多行的 controlname AND brandname AND grouptypes 列相等
  • 然后保留组名不是“Keine Zuordnung”的行。
CONTROLNAME   BRANDNAME   GROUPTYPES    GROUPNAME
ECU AUDI VERNETZER 1
ECU AUDI VERNETZER Keine zuordnung <--THIS
ECU AUDI FUSI Keine zuordnung <--THIS
ECU AUDI FUSI 2
ECU2 AUDI FACHANWENDER Keine zuordnung
ECU3 AUDI FACHANWENDER Keine zuordnung

请问我能帮忙吗?谢谢!

最佳答案

这是一种方法:

select t.*
from (select t.*,
count(*) over (partition by controlname, brandname, grouptypes) as cnt
from t
) t
where cnt = 1 or groupname <> 'Keine Zuordnung';

它使用一个窗口函数来获取计数,然后为您的逻辑使用一个where

关于sql - 基于两列删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40157560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com