根据列值删除重复行

Removing duplicate rows based on column value

我有一个下面的查询,它正在运行,但是 NRLG_SMAINT 的某些属性对于同一属性 ROADLOG/HPMS 不是 Y,我想删除重复的行。我不介意任何 NRLG_SMAINT 属性是否不是 Y,但如果它是 Y,我不希望该行在有 Y 的地方显示相同的 ROADLOG/HPMS 属性。查询如下:

select t.nrlg_dept_route || t.nrlg_dept_roadbed as roadlog,s.HPMS,t.nrlg_smaint
from TIS.TIS_NEW_ROADLOG t right join HPMS_DATA s
on t.nrlg_dept_route || t.nrlg_dept_roadbed = s.hpms
group by t.nrlg_dept_route || t.nrlg_dept_roadbed,s.HPMS,t.nrlg_smaint
order by 1

这是到目前为止的输出示例:

                ROADLOG       HPMS      NRLG_SMAINT
          85    C001821N    C001821N    
          86    C001992N    C001992N    
          87    C005201N    C005201N    Y
          88    C005201N    C005201N    --- remove this row
          89    C005202E    C005202E    Y
          90    C005202E    C005202E    --- remove this row
          91    C005203N    C005203N    Y
          92    C005203N    C005203N    --- remove this row
          93    C005205N    C005205N    Y
          94    C005205N    C005205N    
          95    C005207S    C005207S    --- leave this row
          96    C005208N    C005208N    Y
          97    C005208N    C005208N    
          98    C005209N    C005209N    Y
          99    C005209N    C005209N    

我想你想修复聚合:

select t.nrlg_dept_route || t.nrlg_dept_roadbed as roadlog,
       s.HPMS,
       max(t.nrlg_smaint) as nrlg_smaint
from  HPMS_DATA s left join
      TIS.TIS_NEW_ROADLOG t 
      on t.nrlg_dept_route || t.nrlg_dept_roadbed = s.hpms
group by t.nrlg_dept_route || t.nrlg_dept_roadbed, s.HPMS
order by 1