根据列值删除重复的行

时间:2019-01-02 21:17:52

标签: sql oracle11g plsqldeveloper

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

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    

1 个答案:

答案 0 :(得分:2)

我认为您想解决聚合问题

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