我有 2 个表,分别名为TBL_FIBER_INV_JOBS
和TBL_FIBER_INV_JOB_PROGRESS
。以下是这两个表的描述
TBL_FIBER_INV_JOBS (Master Table) & TBL_FIBER_INV_JOB_PROGRESS (Child Table)
TBL_FIBER_INV_JOBS (Master Table)
Name Null? Type
------------------------- -------- --------------
JOB_ID NOT NULL NUMBER
SPAN_ID NVARCHAR2(100)
LINK_ID NVARCHAR2(100)
CREATED_BY NVARCHAR2(200)
CREATED_DATE NOT NULL DATE
MAINTENANCEZONECODE NVARCHAR2(50)
MAINTENANCEZONENAME NVARCHAR2(100)
MAINT_ZONE_NE_SPAN_LENGTH NUMBER(10,4)
SPAN_TYPE NVARCHAR2(20)
JOB_FLAG NUMBER
MISSING_ABD_LENGTH NUMBER(38,10)
REOFFERFLAG VARCHAR2(10)
TBL_FIBER_INV_JOB_PROGRESS (Child Table)
Name Null? Type
---------------------- -------- --------------
JOB_PROGRESS_ID NOT NULL NUMBER
JOB_ID NUMBER
STATUS_ID NUMBER
APPROVED_BY NVARCHAR2(200)
APPROVED_DATE DATE
REJECTED_BY NVARCHAR2(200)
REJECTED_DATE DATE
APPROV_REJECT_REMARK NVARCHAR2(255)
DELAY_REASON NVARCHAR2(255)
ISABDMISSING NUMBER
HOTO_OFFERED_LENGTH NUMBER
LIT_OFFERED_LENGTH NUMBER
HOTO_ACTUAL_LENGTH NUMBER
LIT_ACTUAL_LENGTH NUMBER
ABD_COMPLETED_LENGTH NUMBER
NE_SPAN_LENGTH NUMBER(10,4)
CREATED_BY NVARCHAR2(200)
CREATED_DATE NOT NULL DATE
MODIFIED_BY NVARCHAR2(200)
MODIFIED_DATE DATE
UMS_GROUP_ASS_BY_ID NUMBER
UMS_GROUP_ASS_BY_NAME NVARCHAR2(200)
UMS_GROUP_ASS_TO_ID NUMBER
UMS_GROUP_ASS_TO_NAME NVARCHAR2(200)
UMS_GROUP_ASS_TO_DATE DATE
JOB_PROGRESS_FLAG NOT NULL NUMBER
因此情况是JOB_ID
子表中可以有多个具有唯一性的JOB_PROGESS_ID
。现在我想要的是
JOB_PROGESS_ID
我总是希望在子表的一个条件下获得最大值的过程JOB_ID
是
子表的条件:-UMS_GROUP_ASS_BY_NAME = 'CMM'
和UMS_GROUP_ASS_TO_NAME IS NULL
。我只想要主表中的 3 列,即JOB_ID, SPAN_ID, LINK_ID
由于我无法获取JOB_PROGRESS_ID
特定 的最大值JOB_ID
。请提出建议
更新
我尝试了以下查询,但它并不准确。
select max(job_progress_id),hoto_actual_length from tbl_fiber_inv_job_progress where job_id = 86753 and ums_group_ass_by_name='CMM' and ums_group_ass_to_name is null group by hoto_actual_length;
select max(job_id), span_id, job_flag,nvl(missing_abd_length,0) missing_abd_length, maint_zone_ne_span_length, maintenancezonecode from tbl_fiber_inv_jobs where job_id = 86753 and job_flag = 0 and span_type <> 'FTTX' group by span_id, job_flag,missing_abd_length, maint_zone_ne_span_length,maintenancezonecode; -- 187375
它不是连接(连同聚合和一些过滤器)吗?
或者,也许使用 CTE?
[编辑]您评论说您需要另一个 (历史记录) 表中的数据。我的理解如下: