如何在 Oracle SQL 中对同一个 table 进行查找和过滤数据

how to do lookup and filter data on the same table in Oracle SQL

在SQL中,我们需要从table中过滤掉不需要的数据:

非常感谢您的帮助。

谢谢

您可以为此使用分析函数:

select t.*
from (
    select 
        t.*, 
        sum(case when dod is null then 1 else 0 end) over(partition by id) no_nulls
    from mytable t
) t
where no_nulls = 0

请注意,这也排除了没有重复 iddodnull 的记录(您没有描述如何处理这些记录)。

您也可以使用 not exists(如果需要,可以方便地转换为 delete 语句):

select t.*
from mytable t
where not exists(select 1 from mytable t1 where t1.id = t.id and t1.dod is null)
where no_nulls = 0