先看下我的测试数据库

查询重复数据只显示一条并且在规定范围时间内

每一个pid都代表一个人员id,这张表下有n条同样的id数据但是时间可以不同

去除重复数据只显示一条 在2020-07-01 00:00:00 -  2020-10-31 23:59:59这个时间段的数据

sql代码:

select *
  from st_death t
 where 1 = 1
   and t.id in (select Max(id) from st_death t group by pid) 
   and 
    (to_char(t.VERIFICATION_TIME, 'YYYY-MM-DD hh:mm:ss')    >='2020-07-01 00:00:00' and to_char(t.VERIFICATION_TIME, 'YYYY-MM-DD hh:mm:ss') <= '2020-10-31 23:59:59') order by t.ssqh,t.verification_time

其中

 and t.id in (select Max(id) from st_death t group by pid) 

作用:去除重复数据显示一条

  我也是参考其他大佬的例子如果有更好的可以在下方评论。。。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
  • 2021-07-25
  • 2021-11-20
  • 2021-12-25
  • 2021-12-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2021-07-15
  • 2021-11-19
  • 2021-06-19
相关资源
相似解决方案