数据库中授信表字段如下:

授信时间(create_time) 客户来源渠道(dept_id) 客户id(user_id) 客户额度(cash)
2020/3/12 13:04:31 aa001 100036 ¥20,000.00

其中共有100个不同客户来源渠道,每个渠道10000个客户,一共100万条数据。

现在需取出100个渠道,每个渠道的最后授权时间对应的这条记录的四个字段。

select create_time , dept_id, user_id ,cash  
from (select *, rank()over(partition by dept_id order by create_time desc) m 
      from table ) table1
where table1.m = 1
select create_time , dept_id ,user_id, cash
from table
where (create_time,dept_id) in 
	  (select max(create_time),dept_id from table group by dept_id)

参考链接:https://blog.csdn.net/weixin_44547599/article/details/88764558

相关文章:

  • 2022-12-23
  • 2022-02-09
  • 2021-06-29
  • 2021-07-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-25
相关资源
相似解决方案