select a.job_id, a.job_name, a.job_group, a.invoke_target, a.cron_expression, a.misfire_policy, a.concurrent, a.status, a.create_by, a.create_time, a.remark, a.job_des, a.cron_des, b.status as last_execute_status, b.create_time as last_execute_time from sys_job a left join sys_job_log b ON a.job_name = b.job_name and a.job_group = b.job_group where b.create_time = (select max(create_time) from sys_job_log c where a.job_name = c.job_name and a.job_group = c.job_group) or b.create_time is null 此SQl为Oracle运行环境,因为sys_job_log有create_time相同的数据导致了数据重复,要保留sys_job 的全部数据,如何解决
时间: 2024-03-15 09:45:29 浏览: 64
Test_invoke_interface.rar_INVOKE.INVOKE_interface
5星 · 资源好评率100%
可以使用ROW_NUMBER()函数来对sys_job_log表中的数据进行编号,然后根据编号选择最新的一条数据。具体的SQL语句如下:
```
SELECT a.job_id, a.job_name, a.job_group, a.invoke_target, a.cron_expression, a.misfire_policy, a.concurrent, a.status, a.create_by, a.create_time, a.remark, a.job_des, a.cron_des, b.status AS last_execute_status, b.create_time AS last_execute_time
FROM sys_job a
LEFT JOIN (
SELECT job_name, job_group, status, create_time, ROW_NUMBER() OVER (PARTITION BY job_name, job_group ORDER BY create_time DESC) AS rn
FROM sys_job_log
) b ON a.job_name = b.job_name AND a.job_group = b.job_group AND b.rn = 1
```
这样可以避免重复数据的问题,同时保留sys_job的全部数据。
阅读全文